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

Hi all,

I want to use the values of a variable in a dataset as macro variables in other procedure. I'm using the CALL SYMPUT option but something is wrong. Consider the follow example.


DATA nowanted;
infile datalines truncover;
input variables $ freq :$10.;
datalines;
Var3 100
Var6 100
Var8 100
run;


DATA fulldata;
INFILE datalines truncover;
INPUT (Var1 - Var8) ($);
datalines;
20 50 20 80 45 50 20 60
20 20 20 80 50 50 30 60
50 50 20 50 45 50 30 60
50 30 20 50 50 50 50 60
30 30 20 80 50 50 30 60
run;

 

DATA _null_;
SET nowanted;
CALL SYMPUT ("macrovar", variables);
run;


%put variables to drop from the fulldata are &macrovar;


DATA datahold; RUN; *empty data set to hold results;

DATA Final; SET datahold fulldata(DROP=&macrovar);
RUN;


In the results,the Final dataset the var8 is dropped but not the Var3 and Var6 variables as is expected.

 

Any suggestion?

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Trace your code:

 

Line1 - set macrovar to var3

Line2 - set macrovar to var6

Line3 - set macrovar to var8

 

Macro variable resolves to var8 -> you've erased the previous values in each iteration.

 

You need to create multiple macro variables or use SQL to select them all into one macro variable. I recommend the SQL solution:

 

 

proc sql;
select variables into :var_list separated by " ";
quit;

%put &var_list;

View solution in original post

1 REPLY 1
Reeza
Super User

Trace your code:

 

Line1 - set macrovar to var3

Line2 - set macrovar to var6

Line3 - set macrovar to var8

 

Macro variable resolves to var8 -> you've erased the previous values in each iteration.

 

You need to create multiple macro variables or use SQL to select them all into one macro variable. I recommend the SQL solution:

 

 

proc sql;
select variables into :var_list separated by " ";
quit;

%put &var_list;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 1 reply
  • 5645 views
  • 1 like
  • 2 in conversation