BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kashili
Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Linlin
Lapis Lazuli | Level 10

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)

View solution in original post

4 REPLIES 4
Peter_C
Rhodochrosite | Level 12

please show the code you use    

kashili
Calcite | Level 5

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)

Linlin
Lapis Lazuli | Level 10

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)

kashili
Calcite | Level 5

super..it works. you made my first post on this website productive. thank you

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 802 views
  • 2 likes
  • 3 in conversation