How can i place 3 macro variables inside of another macro variable without resolving them until it reaches a data step:
%LAT ALL1 = ID_1 NM_1 ID_2 NM_2... NM_10;
%LAT ALL2 = ID_21 NM_21 ID_22 NM_22... NM_30;
%LAT ALL3 = ID_31 NM_31 ID_32 NM_32... NM_40;
%LET COL = &ALL1 &ALL2 &ALL3;
DATA SIMON;
RETAIN &COL.;
SET SIMON;
RUN;
DATA SIMON;
RETAIN ID_1 NM_1 ID_2 NM_2 ... NM_40;
SET SIMON;
RUN;
THE NUMBER OF ALL# VARIABLES CAN CHANGE SO I CAN'T HARD CODED, IT CAN BE A TIME THAT WOULD BE UP TO &ALL5.
Easiest way is to use CALL SYMPUTX(). That way the value can be quoted with single quotes to prevent macro expansion, but the single quotes are not part of the value.
data _null_;
call symputx('COL','&ALL1 &ALL2 &ALL3');
run;
Are any of those named variables in your data set Simon? If so
DATA SIMON;
RETAIN &COL.;
SET SIMON;
RUN;
Does nothing that this doesn't:
DATA SIMON;
SET SIMON;
RUN;
Retained variables that are in a dataset on the SET statement are overwritted by the value in dataset each time the Set executes.
The frequent use of the
Data simon;
set simon;
run;
program structure (in and out the same dataset name) is asking for a headache at some point trying to find where did my variable go or how did it get that value.
By Any chance are you looking for a way to only have the variables in the resulting data set?
Perhaps a KEEP statement?
data new;
set simon (keep= Id_1-Id_10 Id_21-Id_40 NM_1-NM_10 NM_21-NM_40 );
run;
Note the use of variable list for variables with common name varying in an index value.
Easiest way is to use CALL SYMPUTX(). That way the value can be quoted with single quotes to prevent macro expansion, but the single quotes are not part of the value.
data _null_;
call symputx('COL','&ALL1 &ALL2 &ALL3');
run;
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.