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 (March 1997, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 12 Mar 1997 09:33:50 -0800
Reply-To:     mackce@dshs.wa.gov
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Curtis Mack <mackce@DSHS.WA.GOV>
Organization: Washington State Department of Social and Health Services
Subject:      Re: Marco assistance
Content-Type: text/plain; charset=us-ascii

Alderton, David wrote: > > Does anyone have an example of a simple macro that accepts a list of > unrelated items and uses the list to, e.g., subset datasets? > > Right now I'm using a %let / %include pair like this: > > %let oi=TB; > %include "&oi_path"; > > %let oi=PLB; > %include "&oi_path"; > > etc., > > The include file consists of a bunch of simple file manipulations dependent > upon the value of &oi, e.g., as below (actually, 4 sets of the following > within each include). > > proc freq data=New_ASD ; > weight asd_wgt ; > table &oi / out=asdwt noprint ; > by dyr; > run; > > data asdwt; > set asdwt; > retain cnt 0 ; > by dyr; > if first.dyr then cnt=count; > else cnt=cnt+count; > asdwtper=percent; > asdwt=count; > asdwt_N=cnt; > label asdwtper='ASD weighted %'; > if &oi='0' then delete; > drop &oi count cnt percent; > run; > > One of the problems I'm having is that the OI list is an unrelated series of > character strings, TB, PC, MAV, WAST, KS, CERV_CA, etc. (27 of them is the > maximum) and I don't know how to frame this in a macro context. The include > works just fine but I thought I would look for a macro solution to learn how > to do it and to keep all of the code in the same file. > > Any suggestions or samples would be greatly appreciated. I've been looking > at the SAS guide to macro processing (version 6) and SAS Macro Facility but > I cannot find an example that appears to be similar enough for me to grasp > the relationship. Most of the examples use names generated from a list, > like week1, week2, week3, etc. > > Thanks, David. > David L. Alderton, Ph.D. > Centers for Disease Control and Prevention > HIV/AIDS Surveillance Branch > Atlanta, GA -- DLA5@CDC.gov

If I understand your question right I think this is the answer.

%MACRO answer(OI); proc freq data=New_ASD ; weight asd_wgt ; table &oi / out=asdwt noprint ; by dyr; run;

data asdwt; set asdwt; retain cnt 0 ; by dyr; if first.dyr then cnt=count; else cnt=cnt+count; asdwtper=percent; asdwt=count; asdwt_N=cnt; label asdwtper='ASD weighted %'; if &oi='0' then delete; drop &oi count cnt percent; run;

%MEND;

%ANSWER(TB); %ANSWER(PC); %ANSWER(MAV); %ANSWER(WAST); %ANSWER(KS); %ANSWER(CERV_CA); -- Curtis E. Mack Washington State Dept. of Social and Health Services Research and Data Analysis mackce@dshs.wa.gov


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