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;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.