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;

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 4835 views
  • 1 like
  • 2 in conversation