Hello everyone,
I have created a list by %let variables= var1 var2 var3 var4 var5 var6;
would like to use it as below
data _output;
set input(keep=(&variables.)); /*var1--var6 should be taken from here*/
run;
This throws an error but if I do as below, it comes correct.
data _output;
set input;
keep &variables.;
run;
anyone, who has overcame this , please help me know why we can't do like the first step?
A macro is just a code generator.
Compare next two codes - the 1st with parenthesis, the 2nd without:
/* 1 */
data output;
set input (keep=(var1 var2 var3));
run;
/* 2 */
data output;
set input(keep=var1 var2 var3);
run;
The first code is invalid.
Simply loose the inner (). This works
data input;
array var{10} (1 : 10);
run;
%let variables= var1 var2 var3 var4 var5 var6;
data output;
set input(keep=&variables.);
run;
Always test your macro-free code before adding the macro layer. Always.
Here the code is invalid.
A macro is just a code generator.
Compare next two codes - the 1st with parenthesis, the 2nd without:
/* 1 */
data output;
set input (keep=(var1 var2 var3));
run;
/* 2 */
data output;
set input(keep=var1 var2 var3);
run;
The first code is invalid.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.