Monday, April 3, 2017

How to Re-Format / Rename Data (SAS)

This entry addresses two particular issues with data. One being the re-naming of variables within a SAS data sets, the other being the re-formatting of data variables within a SAS data set.

In the case of this example, we are going to assume that you want to re-name and re-format a variable column within a data set.

Here are the steps:

Data NEWSET;  /* Name of the new set */

Set OLDSET;  /* Name of the old set that needs to be corrected */

FixedVar1 = put(Oldvar1, 16.);

FixedVar2 = put(Oldvar2, 16.);

/* Here we are creating two new variable columns from values found in variable columns Oldvar1 and Oldvar2. The PUT function allows for the data variables to be re-formatted as they are assigned. */



/* Now we are dropping the old variables completely from the table */

Rename FixedVar1= Oldvar1;

Rename FixedVar2= Oldvar2;

/* The rename statements now assign the names of the previous variables to the new formatted variables */


The end result of the above listed code creates a new SAS data set that contains the same variable names of the previous data set, however, the formats of the variables will differ.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.