- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 |
AMR001 | 0.82% |
AMR002 | 0.58% |
AMR003 | 0.54% |
AMR004 | 0.57% |
AMR005 | 0.59% |
AMR006 | 0.75% |
AMR007 | 0.64% |
AMR008 | 0.93% |
AMR009 | 0.84% |
AMR010 | 0.66% |
AMR011 | 0.63% |
AMR012 | 0.62% |
AMR013 | 0.99% |
AMR014 | 0.62% |
AMR015 | 0.68% |
AMR016 | 0.70% |
AMR017 | 0.74% |
can anyone guide me how can I do that.
Thanks,
KP
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use Call Symput
data have;
set sashelp.class;
call symput(name, age);
run;
%put &Alfred.;
%put &Jane.;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks everyone
its working