0
votes

I am trying to create a column using the string value of a macro variable in SAS. I have a dataset called want7 which has a column called 'ID'. I want to create a new dataset called want8 with a new column called 'ID1' by dynamically linking it to &string1 (as in the name of the column is linked to &string1) but the values of the column should equal the value of the 'ID' column in want7. How do I do this? Thanks in advance. I have only copied and pasted what I could write since I am relatively new to SAS.

 %let string1 = ID1;
 
 data want8; set want7;
 /*Something like &string1 = ID*
 run;
1
NOTE: All SAS Macro variable values are character (i.e. text) "Macro variables are tools that enable you to dynamically modify the text in a SAS program through symbolic substitution. You can assign large or small amounts of text to macro variables, and after that, you can use that text by simply referencing the variable that contains it." documentation.sas.com/…Richard

1 Answers

1
votes

Using sashelp.class as an example (because it exists by default). Substitute as needed:

 %let string1 = ID1;
 
 data want8; 
    set sashelp.class;
        &string1 = age ;
 run;

This will reread the dataset. If you just want renames, look at the dataset option rename=. See SAS documentation: https://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000695119.htm