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 oldest;  /* 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. */

    drop OldVar1 OldVar2;

/* 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.