Hello everybody,
How to use symput in data step to put a variable's each value of each oberservations into batch of macro variables?
data _null_;
set sashelp.class end=eof;
do until (eof);
call symput('aa'||_n_,sex);
end;
stop;
run;
%put &aa1 &aa2;
hi ... you might also consider SYMPUTX to reduce the length of the macro variables, for example ...
data _null_;
set sashelp.class (obs=2);
call symput(cats('aa',_n_),name);
call symputx(cats('bb',_n_),name);
run;
%put |&aa1| |&aa2|;
%put |&bb1| |&bb2|;
123 %put |&aa1| |&aa2|;
|Alfred | |Alice |
124 %put |&bb1| |&bb2|;
|Alfred| |Alice|
also, the various CAT functions do not give you log messages when concatenating numeric variables such as _N_
CATS applies STRIP to each argument so I don't think it's necessary to add the STRIP function within CATS
data _null_;
set sashelp.class end=eof;
*do until (eof);
call symput('aa'||left(_n_),sex);
*end;
*stop;
run;
%put &aa1 &aa2;
or
data _null_;
set sashelp.class ;
call symputx(cats('aa',strip(_n_)),sex);
run;
%put _user_;
hi ... you might also consider SYMPUTX to reduce the length of the macro variables, for example ...
data _null_;
set sashelp.class (obs=2);
call symput(cats('aa',_n_),name);
call symputx(cats('bb',_n_),name);
run;
%put |&aa1| |&aa2|;
%put |&bb1| |&bb2|;
123 %put |&aa1| |&aa2|;
|Alfred | |Alice |
124 %put |&bb1| |&bb2|;
|Alfred| |Alice|
also, the various CAT functions do not give you log messages when concatenating numeric variables such as _N_
CATS applies STRIP to each argument so I don't think it's necessary to add the STRIP function within CATS
Thank you Milke! It is good to know. - Linlin
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.