LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 1996, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 6 Aug 1996 09:11:41 EDT
Reply-To:     whitloi1@WESTATPO.WESTAT.COM
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Ian Whitlock <whitloi1@WESTATPO.WESTAT.COM>
Subject:      Re: Q: a macro question
Comments: To: Sung-Il Cho <sungil@HOHP.HARVARD.EDU>

Subject: Q: a macro question Summary: Use macaro variables to remove repetitive decisions. Respondent: Ian Whitlock <whitloi1@westat.com>

Sung-Il Cho <sungil@HOHP.HARVARD.EDU> asks how to eliminate the repetitive nature of the %IFs in his macro

> %macro summary(data=, expo=, disease=, stratum=, freq=, > e_code=hi, d_code=low); > > proc sort data=&data; by &stratum > %if %upcase(%substr(&d_code,1,2))= HI %then %str(descending); > &disease > %if %upcase(%substr(&e_code,1,2))= HI %then %str(descending); > &expo ; > proc means n noprint data=&data; > var &disease; by &stratum > %if %upcase(%substr(&d_code,1,2))= HI %then %str(descending); > &disease > %if %upcase(%substr(&e_code,1,2))= HI %then %str(descending); > &expo ; > %if %quote(&freq) ne %then %str( freq &freq; ); > output out=temp(drop=_type_ _freq_) n=count; > run; > proc print; run; > %mend summary;

The repetition comes from making the same decision more than once. To eliminate it hold the decision in a macro variable and then refer to the macro variable in multiple places.

%macro summary(data=, stratum=, freq=, e_code=hi, expo=, d_code=low, disease= );

%local emod dmod ; %if %upcase(%substr(&d_code,1,2))= HI %then %let dmod = descending ; %if %upcase(%substr(&e_code,1,2))= HI %then %let emod = descending ;

proc sort data=&data; by &stratum &dmod &disease &emod &expo ; run ;

proc means n noprint data=&data; var &disease; by &stratum &dmod &disease &emod &expo ; %if %quote(&freq) ne %then %str( freq &freq; ); output out=temp(drop=_type_ _freq_) n=count; run;

proc print data = temp ; run;

%mend summary;

I would consider modifying the parameter structure to:

%summary(data=lib1.chd1, stratum=stratum, freq=freq, expo=descending expo, disease=disease )

This form has fewer parameters for the user to remember. Now, of course, the macro code gets longer and more complex, but it might be easier to use.

Ian Whitlock <whitloi1@westat.com>


Back to: Top of message | Previous page | Main SAS-L page