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

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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)


View solution in original post

7 REPLIES 7
Tom
Super User Tom
Super User

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)


robertrao
Quartz | Level 8

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.

Tom
Super User Tom
Super User

No. I just didn't want to retype the whole thing. Hence the use of ellipses (...) in my sample code.

robertrao
Quartz | Level 8

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

Tom
Super User Tom
Super User

Yes.  I just did that to show that you are not limited to a single parameter.

Reeza
Super User

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

robertrao
Quartz | Level 8

Thanks Reeza

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is ANOVA?

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.

Discussion stats
  • 7 replies
  • 1574 views
  • 3 likes
  • 3 in conversation