Date: Tue, 6 Aug 1996 18:53:52 GMT
Reply-To: Frank Liu <fliu@WORLD.STD.COM>
Sender: "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From: Frank Liu <fliu@WORLD.STD.COM>
Organization: The World Public Access UNIX, Brookline, MA
Subject: Re: Q: a macro question
Hi, Cho:
Pls try the following codes:
%macro summary(data=, expo=, disease=, stratum=, freq=,
e_code=, d_code=);
%if %upcase(%trim(&d_code))=HI
%then %let by_dis=%str( BY &STRATUM DESCENDING &DISEASE;);
%if %upcase(%trim(&e_code))=HI
%then %let by_expo=%str( BY &STRATUM DESCENDING &EXPO );
title "&disease ....";
proc sort data=&data ;
%unquote(&by_dis);
title "&expo...";
proc sort data=&data;
%unquote(&by_expo);
.
.
.
%mend;
It should work. Do not split BY statement or VAR statement in this case.
Good luck.
Frank Liu
Genzyme, Inc.
One Kendall Square
Cambridge, MA 02139.
(617)374-7262 (W)
--------------------------------------------------------------------------
Sung-Il Cho (sungil@HOHP.HARVARD.EDU) wrote:
: 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
|