SAS Programming

DATA Step, Macro, Functions and more
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

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 600 views
  • 1 like
  • 3 in conversation