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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.