Assign value to variable from table using

Reply
Occasional Contributor
Posts: 14

Assign value to variable from table using

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

Super User
Posts: 19,862

Re: Assign value to variable from table using

Posted in reply to Kpatel306

Use Call Symput

data have;

set sashelp.class;

call symput(name, age);

run;

%put &Alfred.;

%put &Jane.;

Super Contributor
Posts: 339

Re: Assign value to variable from table using

Posted in reply to Kpatel306

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.

Occasional Contributor
Posts: 14

Re: Assign value to variable from table using

Posted in reply to Kpatel306

Thanks everyone

its working

Ask a Question
Discussion stats
  • 3 replies
  • 317 views
  • 0 likes
  • 3 in conversation