BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

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. 

View solution in original post

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

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;
ChrisNZ
Tourmaline | Level 20

Always test your macro-free code before adding the macro layer. Always.

Here the code is invalid.

Shmuel
Garnet | Level 18

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. 

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1153 views
  • 0 likes
  • 4 in conversation