BookmarkSubscribeRSS Feed
Kpatel306
Calcite | Level 5

Hi,

Anybody can help me on - how to create a macro variable using SYMPUT (or if is there any other way ) to crate the macro variable and to assign a value from table.

e.g.;

from below table I want to assign value 0.82% to AMR001, 0.58% to AMR002 and so forth.

Variable Value
AMR0010.82%
AMR0020.58%
AMR0030.54%
AMR0040.57%
AMR0050.59%
AMR0060.75%
AMR0070.64%
AMR0080.93%
AMR0090.84%
AMR0100.66%
AMR0110.63%
AMR0120.62%
AMR0130.99%
AMR0140.62%
AMR0150.68%
AMR0160.70%
AMR0170.74%

can anyone guide me how can I do that.

Thanks,

KP

3 REPLIES 3
Reeza
Super User

Use Call Symput

data have;

set sashelp.class;

call symput(name, age);

run;

%put &Alfred.;

%put &Jane.;

Vince28_Statcan
Quartz | Level 8

you can simply do

data _null_;

     set have;

     call symputx(variable, value);

run;

after which &AMR001 will deref to 0.82%. You may need to validate that the value stored in the macro is that which you wanti t to be represented (it could be 0.0082 or 0.82% depending on your requirements).

Typically, you would add a a mean to count the number of variable created such as

data _null_;

     set have end=eof;

     call symputx(variable, value);

     if eof then do;

     call symputx('nvar', _N_);

     end;

run;

The issue with this is that it does not really give you explicit indexing of 001, 002 etc. That is, you need to know beforehand the values of AMR### that are in your dataset and you need to be absolutely sure that they are consistent.

Kpatel306
Calcite | Level 5

Thanks everyone

its working

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 5358 views
  • 0 likes
  • 3 in conversation