Hi all,
I have a list of values as below and want to assign macro variables (num_val&i.) like num_val1 for 0.5, num_val2 for 0.9, ... num_val5 for 2. Can anyone help me out? Thank you!
data have;
infile datalines truncover dsd;
input num_val;
datalines;
0.5
0.9
1.1
1.5
2
;
run;
Try this
proc sql noprint;
select num_val into :num_val1 -
from have
;
quit;
%put &=num_val1.;
%put &=num_val2.;
Try this
proc sql noprint;
select num_val into :num_val1 -
from have
;
quit;
%put &=num_val1.;
%put &=num_val2.;
In general, I am skeptical that this is a good approach. Can you please share with us what you will do with these macro variables once they are created, that cannot be done using data set HAVE?
Anyway, here is the code you want.
data _null_;
set have;
call symputx(cats('num_val',_n_),num_val);
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.