0

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/… Commented Jul 1, 2020 at 11:31

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.