Programming the statistical procedures from SAS

Macro Question

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,040
Accepted Solution

Macro Question

Hi Team,

I wrote a macro and I feel it needs to be tiday. Too many dataset names. Could anybody help me look tidy.

Thanks

%macro age(dname1=,dname2=,dname3=,dname4=,dname5=);

proc means data=&dname1 nway noprint;
var age;
output out=&dname2 n= mean= std= median= min= max=/autoname;
run;

data &dname3;
set &dname2;
keep n meansd median minmax;
n=put(age_N,4.);
meansd=put(age_Mean,4.1)|| " ("||put(age_StdDev,4.1)||" )";
median=put(age_Median,4.1);
minmax=put(age_Min,4.1)  ||"/"|| put(age_Max,4.1);
run;

proc transpose data=&dname3 out=&dname4;
var n meansd median minmax;
run;

data &dname5(drop=_name_);
set &dname4;
stat=put(_name_,$age.);
label="Age (Years)";
run;
%mend;
%age(dname1=one,dname2=two,dname3=three,dname4=four,dname5=five);


Accepted Solutions
Solution
‎10-01-2012 05:15 PM
PROC Star
Posts: 7,416

Re: Macro Question

Karun,

My first question would be "Do you really need to write this as a SAS macro?"  As written, it appears to be quite specific (i.e., not reusable for future tasks) and could easily be done outside of the macro language.

Second, for any code (in or out of macroland), you really should make use of indentation.

Third, do you need all five files or can one or more of them be re-used?

Art

View solution in original post


All Replies
Super Contributor
Posts: 1,040

Re: Macro Question

Sorry...... i meant TIDY

Solution
‎10-01-2012 05:15 PM
PROC Star
Posts: 7,416

Re: Macro Question

Karun,

My first question would be "Do you really need to write this as a SAS macro?"  As written, it appears to be quite specific (i.e., not reusable for future tasks) and could easily be done outside of the macro language.

Second, for any code (in or out of macroland), you really should make use of indentation.

Third, do you need all five files or can one or more of them be re-used?

Art

Super Contributor
Posts: 1,040

Re: Macro Question

Hi Arthur,

There are 5 datasets which goes seperately into dname1(sorry for just putting only a part of my code here)

So I get to reuse it 5 times

Thanks

🔒 This topic is solved and locked.

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

Discussion stats
  • 3 replies
  • 177 views
  • 0 likes
  • 2 in conversation