I am newbie to sas, pl help me if this is possible in sas (if it is a valid question!!). I am using SAS EG
-I have a macro 1)which takes dataset(lets call it as master dataset), 2)does few things to master dataset and 3)then outs 10 new datasets(decile datasets) using proc rank
-in 'output data' window I can see the master dataset and 10 decile dataset and I can export them to excel file and everything is fine.
-above works if I call macro only once. If I call this macro more than once, then I see the values for only 1 decile dataset (apparently they are being overwritten)
How can I distinguish between the naming of decile datasets of one master set with the naming of other decile datasets (so that I can preserve them).
May be I can make the decile datasetname unique by appending the name of master dataset name that I get in macro (is this possible)?
or may be should I write the decile datasets to a file (if so how can I retrieve the name of the master dataset from the macro parameter)
thank you
Hi,
try the code below:
%macro LMGenerate(mymktdata);
proc rank data=&mymktdata out=deciledrankedscores ties= low descending groups=10;
var LM12value;
ranks decile;
run;
data &mymktdata.decile_0 &mymktdata.decile_1 &mymktdata.decile_2 &mymktdata.decile_3
&mymktdata.decile_4 &mymktdata.decile_5 &mymktdata.decile_6 &mymktdata.decile_7
&mymktdata.decile_8 &mymktdata.decile_9;
set deciledrankedscores;
select(decile);
when (0) output &mymktdata.decile_0;/* can I make this output as..."output nameof(mymktdata)+&mymktdata.decile_0"*/
when (1) output &mymktdata.decile_1;/*I need to change the output data sets names to all of the following in the same naming way as above*/
when (2) output &mymktdata.decile_2;
when (3) output &mymktdata.decile_3;
when (4) output &mymktdata.decile_4;
when (5) output &mymktdata.decile_5;
when (6) output &mymktdata.decile_6;
when (7) output &mymktdata.decile_7;
when (8) output &mymktdata.decile_8;
when (9) output &mymktdata.decile_9;
otherwise;
end;
run;
%mend LMGenerate;
%LMGenerate(yr2011mktdata)
%LMGenerate(yr2010mktdata)
please show the code you use
here is the code
%macro LMGenerate(mymktdata);
proc rank data=mymktdata out=deciledrankedscores ties= low descending groups=10;
var LM12value;
ranks decile;
run;
data decile_0 decile_1 decile_2 decile_3 decile_4 decile_5 decile_6 decile_7 decile_8 decile_9;
set deciledrankedscores;
select(decile);
when (0) output decile_0;/* can I make this output as..."output nameof(mymktdata)+decile_0"*/
when (1) output decile_1;/*I need to change the output data sets names to all of the following in the same naming way as above*/
when (2) output decile_2;
when (3) output decile_3;
when (4) output decile_4;
when (5) output decile_5;
when (6) output decile_6;
when (7) output decile_7;
when (8) output decile_8;
when (9) output decile_9;
otherwise;
end;
run;
%mend LMGenerate;
%LMGenerate(yr2011mktdata)
%LMGenerate(yr2010mktdata)
Hi,
try the code below:
%macro LMGenerate(mymktdata);
proc rank data=&mymktdata out=deciledrankedscores ties= low descending groups=10;
var LM12value;
ranks decile;
run;
data &mymktdata.decile_0 &mymktdata.decile_1 &mymktdata.decile_2 &mymktdata.decile_3
&mymktdata.decile_4 &mymktdata.decile_5 &mymktdata.decile_6 &mymktdata.decile_7
&mymktdata.decile_8 &mymktdata.decile_9;
set deciledrankedscores;
select(decile);
when (0) output &mymktdata.decile_0;/* can I make this output as..."output nameof(mymktdata)+&mymktdata.decile_0"*/
when (1) output &mymktdata.decile_1;/*I need to change the output data sets names to all of the following in the same naming way as above*/
when (2) output &mymktdata.decile_2;
when (3) output &mymktdata.decile_3;
when (4) output &mymktdata.decile_4;
when (5) output &mymktdata.decile_5;
when (6) output &mymktdata.decile_6;
when (7) output &mymktdata.decile_7;
when (8) output &mymktdata.decile_8;
when (9) output &mymktdata.decile_9;
otherwise;
end;
run;
%mend LMGenerate;
%LMGenerate(yr2011mktdata)
%LMGenerate(yr2010mktdata)
super..it works. you made my first post on this website productive. thank you
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: