Are you trying to create a single macro variable or many here? Personally, I find SQL easier to use in these cases.
Multiple macro variables:
Proc sql noprint;
Select name into : name1-
From sashelp.class;
Quit;
%put &name1.;
%put &name19.;
Single macro variable, delimited by space:
Proc sql noprint;
Select name into :name_list separated by “ “
From sashelp.class;
Quit;
%put &name_list;
The following datastep creates a single macro variable for each record in your set and a variable that has the count.
Data _null_; Set sample; mvarname= catt('name',_n_); Call symputx(mvarname,name); call symputx('numnames',_n_); Run;
Old school, as in SAS 6. I would go with @Reeza's Proc SQL most of the time these days.
@Sharathr please choose someone else's answer as the solution, not your own.
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.