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 20:23:45 -0600
Reply-To:     Scott Came <came.s@GHC.ORG>
Sender:       "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:         Scott Came <came.s@GHC.ORG>
Organization: Deja News Usenet Posting Service
Subject:      Re: Marco assistance

In article <3326520D@SmtpOut.em.cdc.gov>, "Alderton, David" <dla5@CIDHIV1.EM.CDC.GOV> 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

David:

You can probably do what you need to do by using scan() to step through the list items one by one.

/* put the list into a macro variable. okay to span more than one line */

%let list=TB PC MAV WAST KS CERV_CA;

%macro main(maclist);

%local loclist nthings i curr_wd;

%* take out any double spaces, eols *;

%let loclist=%cmpres(&maclist);

%* count the number of words *;

%if &loclist= %then %let nthings=0; %else %let nthings=%eval(%sysfunc(length(&loclist)) - %sysfunc(length(%sysfunc(compress(&loclist)))) + 1);

%* loop through the words *;

%do i = 1 %to &nthings;

%let curr_wd = %sysfunc(scan(&loclist,&i));

%put Current word is --> &curr_wd;

%* (of course, you will do non-trivial processing here, using macro variable curr_wd in your tables, datasteps, etc.) *;

%end;

%mend main; %main(&list)

Good luck!! (Worked okay on 6.11 under Win 95.)

Scott Came Sr Programmer/Analyst Group Health Cooperative of Puget Sound Seattle, Washington

-------------------==== Posted via Deja News ====----------------------- http://www.dejanews.com/ Search, Read, Post to Usenet


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