x cd /pub/data/sf12010x/Tools; %let pgm=do_county_reports; filename pgm "&pgm..sas"; *--Generate a series of county level reports using a revised docos macro. jgb, 8-11. ---*; %macro docos( /* This macro facilitates processing all or selected counties within a state. The user writes a macro (named doit) which takes 2 positional parms that accept the values of the county fips code and its name. The macro accesses the county codes and names from a sas formats catalog entry such as can be defined using the mcdc Scounty.sas module in our /pub/sas/formats library. */ state=29, /* fips state code. Can only do one state at a time */ cos=, /* optional list of 5-digit w leading zero fips county codes for which the macro is to be invoked. If left blank and minco/maxco are not specified then all counties in the state are processed. */ mac=doit, /* name of the macro that does the processing. Takes 2 positional parms: the county code and the county name. The latter will be passed a value iff the names parm has a value of 1 */ names=0, /* specify a value of 1 to get the county name and pass it to the macro */ msgs=0, /* set to 1 if you want a message to appear on the log prior to each macro invocation */ minco=,maxco=, /* these 2 parms form a pair. Specify none or both. Values of 06005,06013 would process all counties starting with 06005 and ending with 06013. 5-digit with leading zeroes required. */ sasctlgs=sasctlgs, /* libref of the location of the formats catalog. The county codes and names are assumed to be stored as the args & labels in &sasctlgs..formats. The name of the character format is specified via next parm */ fmtname=county, /* $county. actually . Name of format module stored in &sasctlgs..formats. */ revdate=04Aug11); %*--does for counties what dostates does for states, more or less. --; %local counties cnames i ncos county cnytname; %local null; %if &minco ne &null %then %do; %if %length(&minco)=3 %then %let minco=&state&minco; %end; %if &maxco ne &null %then %do; %if %length(&maxco)=3 %then %let maxco=&state&maxco; %end; proc format library= &sasctlgs..formats cntlout=cocodes(keep=start label where=(county=:"&state" and length(county)=5 %if &cos ne %str() %then %do; and index("&cos",trim(county)) %end; %if &minco ne %str() %then %do; and trim(county) ge "&minco" %end; %if &maxco ne %str() %then %do; and trim(county) le "&maxco" %end; and substr(county,3,3) ne '000') rename=(start=County label=CntyName)); select $&fmtname ; run; proc sql noprint; select County into :counties separated by ' ' from cocodes; %if &names %then %do; select CntyName into :cnames separated by '|' from cocodes; %end; %else %let cntyname=%str(); select count(*) into :ncos from cocodes; quit; %*-get a count of the selected counties-; %**put _user_; %*et ncos=%lenlst(&counties); %do i=1 %to &ncos; %let county=%scan(&counties,&i); %if &names %then %do; %let cntyname=%scan(&cnames,&i,%str(|)); %end; %if &msgs %then %put ***Invoking &mac for county &county &cntyname; %&mac(&county,&cntyname) %end; %*--do i loop--; %mend docos; options mprint; %macro doit(cocode,coname); %put &cocode &coname; %mend doit; %docos(state=06,names=1) ;