BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
lichee
Quartz | Level 8

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;

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Try this

 

proc sql noprint;
   select num_val into :num_val1 -
   from have
   ;
quit;

%put &=num_val1.;
%put &=num_val2.;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Try this

 

proc sql noprint;
   select num_val into :num_val1 -
   from have
   ;
quit;

%put &=num_val1.;
%put &=num_val2.;
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 913 views
  • 1 like
  • 3 in conversation