%macro docos(state=29,cos=,mac=doit,names=0,msgs=0,minco=,maxco=, fmatlib=sasctlgs.formats, /* source of county codes unless codataset is specfied */ fmatname=$county, /* name of the format code stored in fmatlib with county codes and names as args and labels */ codataset=, /* if specified then it is used as the source of county codes rather than the format code */ revdate=21JUL12); %*--does for counties what dostates does for states, at least when it is done we expect it to do that-; %*--Coding begins 5-5-02, jgb-; %local counties cnames i ncos county cnytname; %if %superq(codataset) ne %str() %then %do; data cocodes; set &codataset(keep=_character_); where state="&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'); if sumlev ne ' ' then if sumlev='050'; keep county areaname; rename areaname=CntyName; run; %end; %else %do; proc format library= library.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 $county; run; %end; 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(county) into :ncos from cocodes; quit; %*let 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;