May somebody help me with SAS syntax.
Once you have the dataset, creating the macro variable is easy, too:
data myListVars;
length item $32;
do _n_=1 to 5;
item=cats('a',_n_);
output;
end;
run;
proc sql noprint;
select *
into :listvars separated by '|'
from myListVars;
quit;
What are you planning to use this for down the line?
You could use a loop, but there's probably better ways to do whatever you're trying to do is my guess.
data want;
do i=1 to 99;
Item=catt("A", put(i, z2.));
output;
end;
run;
Are you trying to put a list of variable names from a table that already exists into a macro variable? Or, are you trying to create a table with a list of variable names?
Once you have the dataset, creating the macro variable is easy, too:
data myListVars;
length item $32;
do _n_=1 to 5;
item=cats('a',_n_);
output;
end;
run;
proc sql noprint;
select *
into :listvars separated by '|'
from myListVars;
quit;
Thank you very much. This is exactly what I need. I just didn't know the first part.
You're welcome. But if you only need the macro variable, you can get it even more easily:
data _null_;
array x[5] (1:5);
call symputx('listvars', 'a'||catx('|a', of x:));
run;
Thank you! Even better!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.