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 ¯ovar;
DATA datahold; RUN; *empty data set to hold results;
DATA Final; SET datahold fulldata(DROP=¯ovar);
RUN;
In the results,the Final dataset the var8 is dropped but not the Var3 and Var6 variables as is expected.
Any suggestion?
Thanks
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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.