x cd /pub/data/corrlst/Tools; %let pgm=place_to_county; filename pgm "&pgm..sas"; *---Create various place to county correlation list datasets and generate csvfiles with "primary" counties for places. Running for mo and ks, 3-29-01. Uses pl942000 as source. Running Aug. 2001 to generate sets for all states in US as well as a usplco2k set with full u.s. Storing the individual state sets in a subdirectory. Rerun the US dataset creation 3-2004, to add geographic name variables. And again, 10-04 to modify the msaname variable in uspl2k. See permanent format codes $usplco and $moplco, which map fips place codes to primary county codes and names. We use those codes here to do a lookup to assign the new variable Primary (0/1), a flag indicating whether or not the county is the primary county for the place. John Blodgett, OSEDA, U. of Missouri Outreach & Extension ---*; title 'Creating a National Collection of Place to County Correlation Lists'; options nodate; %libname(pl942000); libname corrlst '/pub/data/corrlst'; libname plc2cnty '/pub/data/corrlst/plc2cnty2k'; *--special subdirectory to hold this collection--; %macro doit(state,stab); proc sort data=pl942000.&stab.geos(keep=sumlev state placefp county pop100 msacmsa where=(sumlev='740' and placefp ne '99999')) out=sort&stab; by state placefp county; run; %corrwt(setin=sort&stab,setout=&stab.plco2k,g1=state placefp,g2=county,idvars=msacmsa,wtvar=pop100,keepwt=1); *---sort set so that the "primary" county is first among the obs for a place---; proc sort out=plc2cnty.&stab.plco2k; by state placefp descending pop100; run; /* ***************************** data primary; set corrlst.&stab.plco2k; by state placefp; if first.placefp; length placename $7 cntyname $5; cntyname=county; %if stab=mo %then %do; placename=placefp; format placename $mofplac. cntyname $mocnty.; %end; %else %do; placename=state||placefp; format placename $fplace. cntyname $county.; %end; run; filename dlmout "/pub/data/corrlst/&stab.place_to_primary_county.csv"; %cnvtdlm(setin=primary,names=1,round=.001) run; **************************** */ %mend doit; /*<=========================Comment out===================================== *---invoke a macro for every state in U.S.---; %doit(01,al) ; %doit(02,ak) ; %doit(04,az) ; %doit(05,ar) ; %doit(06,ca) ; %doit(08,co) ; %doit(09,ct) ; %doit(10,de) ; %doit(11,dc) ; %doit(12,fl) ; %doit(13,ga) ; %doit(15,hi) ; %doit(16,id) ; %doit(17,il) ; %doit(18,in) ; %doit(19,ia) ; %doit(20,ks) ; %doit(21,ky) ; %doit(22,la) ; %doit(23,me) ; %doit(24,md) ; %doit(25,ma) ; %doit(26,mi) ; %doit(27,mn) ; %doit(28,ms) ; %doit(29,mo) ; %doit(30,mt) ; %doit(31,ne) ; %doit(32,nv) ; %doit(33,nh) ; %doit(34,nj) ; %doit(35,nm) ; %doit(36,ny) ; %doit(37,nc) ; %doit(38,nd) ; %doit(39,oh) ; %doit(40,ok) ; %doit(41,or) ; %doit(42,pa) ; %doit(44,ri) ; %doit(45,sc) ; %doit(46,sd) ; %doit(47,tn) ; %doit(48,tx) ; %doit(49,ut) ; %doit(50,vt) ; %doit(51,va) ; %doit(53,wa) ; %doit(54,wv) ; %doit(55,wi) ; %doit(56,wy) ; ===========================End commented out================================ */ *-----------Now create the us data set as concatenation of all the states----; %macro setname(state,stab); plc2cnty.&stab.plco2k %mend setname; options mprint; data corrlst.usplco2k(label='U.S. Place to County Per PL94-2000 Pop' sortedby=state index=(state)); set %dostates(mac=setname) open=defer; *---Add geographic names using format codes----; length PlaceName $7; if placefp ne '99999' then PlaceName=State||Placefp; format PlaceName $fplace.; CntyName=county; format cntyname $county. County $5.; if msacmsa ne '9999' then MetroName=msacmsa; format msacmsa $metro.; *--assign primary county flag by doing a format table lookup--; length _arg $7; _arg=state||placefp; drop _arg; if put(_arg,$usplco5.)=county then Primary='1'; else Primary='0'; label msacmsa='Metro Area (MSA or CMSA), 2000' County='County (FIPS)' pop100='Complete Count Pop, 2k Census' afact='Portion of place pop in County'; label Primary ='Primary County Flag'; run; proc contents data=corrlst.usplco2k position; title2 'Contents Report for the corrlst.usplco2k National Place to County Correlation List'; run; proc print data=corrlst.usplco2k (where=(state='29' and county in('29189','29183'))); title2 'Sample Listing of the Missouri Portion of the usplco2k Correlation List';