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:         Mon, 5 Aug 1996 15:52:37 PDT
Reply-To:     TWB2%Rates%FAR@GO50.COMP.PGE.COM
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         TWB2%Rates%FAR@GO50.COMP.PGE.COM
Subject:      Re: Q: a macro question

As macro code goes, this is not particularly wordy. Since you are sure your data IS sorted after the sort, you could use the NOTSORTED keyword on the PROC MEANS BY statement and remove the code to generate DESCENDING (remove it from PROC MEANS--it would still be required in the sort).

I attempted the macro syntax %if &e_code eq: HI %then ..., but it turned out this was testing the value of &e_code against ": HI" rather than truncating the longer value to the length of the sorter value, so that is not a trick to avoid the %substr.

NOTSORTED is normally used if, for instance, you have data sorted by date but you want to use the spelled-out name of the month in a BY statement.

Tim Berryhill - Contract Programmer and General Wizard TWB2@PGE.COM Frequently at Pacific Gas & Electric Co., San Francisco The correlation coefficient between their views and my postings is slightly less than 0 ----------------------[Reply - Original Message]----------------------

Sent by:Sung-Il Cho <sungil@HOHP.HARVARD.EDU> Could somebody teach me how to simplify the following macro codes ?

I tried to control the sorting order of the two variables: &expo, and &disease, by assigning 'high' or 'low' to the other two variables: &e_code, &d_code. The only thing I need is to put 'descending' keyword conditional on the values of &e_code and &d_code.

I ended up with a pretty repetitive lines as below. I tried to make another macro variable or another macro to simplify the repition, but without success.

%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;

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

----------------------------------------------------------- Sung-Il Cho 617-432-1147 (voice) 432-0219 (FAX) Dept. of Env Health (Occupational Health Program) & Dept. of Epidemiology, Harvard School of Public Health 665 Huntington Av., Boston MA 02115

=====================================================================


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