DATA Step, Macro, Functions and more

can I append a dataset name to other datasetname in sas

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 13
Accepted Solution

can I append a dataset name to other datasetname in sas

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


Accepted Solutions
Solution
‎02-17-2013 06:01 PM
Super Contributor
Posts: 1,636

Re: can I append a dataset name to other datasetname in sas

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


All Replies
Valued Guide
Posts: 2,175

Re: can I append a dataset name to other datasetname in sas

please show the code you use    

Occasional Contributor
Posts: 13

Re: can I append a dataset name to other datasetname in sas

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)

Solution
‎02-17-2013 06:01 PM
Super Contributor
Posts: 1,636

Re: can I append a dataset name to other datasetname in sas

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)

Occasional Contributor
Posts: 13

Re: can I append a dataset name to other datasetname in sas

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 210 views
  • 2 likes
  • 3 in conversation