Could you help me build a macro please...
Thanks
ods pdf file="C:\Data\Projects\Dhoom-20120911002\age.pdf";
proc freq data=test;
tables age*Pat/nopercent fisher relrisk;
exact pchi or;
title "Age vs Pat";
run;
proc freq data=test;
tables age*Comp/nopercent fisher relrisk;
exact pchi or;
title "Age vs Comp";
run;
proc freq data=test;
tables age*Any/nopercent fisher relrisk;
exact pchi or;
title "Age vs Any";
run;
ods pdf close;
This piece of code repeats for 11 variables.
in the ods statement the name of the pdf changes next time
tables statement age changs to another next
title for the above next time :Age is replaced with another
Before going all the way to a macro try replacing the parts that change with a macro variable reference.
Example:
%let ds=test;
%let var=age;
ods pdf file="C:\Data\Projects\Dhoom-20120911002\&var..pdf";
proc freq data=&ds;
tables &var*Pat/nopercent fisher relrisk;
exact pchi or;
title "&var vs Pat";
run;
....
Then you can try calling it a couple times changing the value of the macro variables VAR and DS.
Once you have it working you can wrap it in a macro;
%macro report1(ds,var);
ods pdf file=........
....
%mend report1;
Then you can call it 11 times by just writing 11 macro calls with different values for the parameters.
%report1(test,age)
%report1(test,ht)
Before going all the way to a macro try replacing the parts that change with a macro variable reference.
Example:
%let ds=test;
%let var=age;
ods pdf file="C:\Data\Projects\Dhoom-20120911002\&var..pdf";
proc freq data=&ds;
tables &var*Pat/nopercent fisher relrisk;
exact pchi or;
title "&var vs Pat";
run;
....
Then you can try calling it a couple times changing the value of the macro variables VAR and DS.
Once you have it working you can wrap it in a macro;
%macro report1(ds,var);
ods pdf file=........
....
%mend report1;
Then you can call it 11 times by just writing 11 macro calls with different values for the parameters.
%report1(test,age)
%report1(test,ht)
Tom,
The three freqs shown above constitutes a block.
I have to compute 11 blocks like that.
I think u misunderstood the 3 freqs shown above for 3 blocks.
No. I just didn't want to retype the whole thing. Hence the use of ellipses (...) in my sample code.
Ok Got u.
But in the second block also the dset name is the same. So i can keep it intact right instead of assigning it a macro variable reference???
Thnx
Yes. I just did that to show that you are not limited to a single parameter.
Why write your own?
Do some googling to get the code and then dissect it instead with some put statements. Unless you're doing it as a learning exercise instead of work....
Here's an example of one that I've used before and like, the summary one. And if its not what you want, at least you have an idea of how to create the macro and where to start instead of scratch.
http://mayoresearch.mayo.edu/mayo/research/biostat/sasmacros.cfm
Thanks Reeza
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.