I want to store values of macro variable "&macvar" in a data set.
%macro m;
proc sql noprint;
select distinct name
into: macvar separated by ' '
from sashelp.class;
quit;
%put &macvar;
data _null_;
%do i= 1 %to 19;
%put %scan(&macvar,&i,' ');
%end;
run;
%mend m;
%m
OK, still not too difficult. Here's the basic idea:
data want;
length value $ 32;
do i=1 to countw("&macvar");
value = scan("&macvar", i, ' ');
output;
end;
run;
I'm not sure if there might be a set of special characters that COUNTW would treat as delimiters (besides a blank). You might have to modify the DO statement to account for that, if &MACVAR might contain special characters.
If you want the individual NAME values stored separately, you don't need the macro variable:
proc sql;
create table want as select distinct name from sashelp.class;
quit;
If you want the entire string stored as one long DATA step variable, you could use:
data want;
value = "&macvar";
run;
@Astounding. I was trying to process the list (&macvar) and output each value in a data set (such as using OUTPUT statement).
OK, still not too difficult. Here's the basic idea:
data want;
length value $ 32;
do i=1 to countw("&macvar");
value = scan("&macvar", i, ' ');
output;
end;
run;
I'm not sure if there might be a set of special characters that COUNTW would treat as delimiters (besides a blank). You might have to modify the DO statement to account for that, if &MACVAR might contain special characters.
@Astounding. Thank you. This is what I was looking for.
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.