x cd /pub/sas/formats/Tools; %let pgm=genplace; filename pgm "&pgm..sas"; *--regenerate the $place format code from a combination of 2000, 2009 and 2010 using the genfmat macro.--; *---running 11-30-11 with 2010 sf1 as new data source, but keeping places from 2000 even if they no longer exist--; filename text '/pub/sas/formats/Splace.sas'; libname user '/SAS_temp/user'; %libname(sf1prof); %libname(popests); %libname(sf12010); data forfmat; merge sf1prof.us(in=in1 keep=sumlev state areaname placefp where=(sumlev='160')) popests.ussc09(in=in2 keep=sumlev state areaname placefp stab where=(sumlev='162')) sf12010.usinventory(in=in2010 keep=sumlev state placefp areaname stab where=(sumlev='160')); *---will probably want to use usplaces instead if rerun later since we plan to delete usinventory---; by state placefp; length status $8; if not in1 then status='New'; else if not in2010 then status='Defunct'; if not in2 and not in2010 then do; _ix=index(areaname,','); if _ix then areaname=substr(areaname,1,_ix)||' '||put(state,$fipstab2.); end; else Areaname=trim(Areaname)||', '||upcase(stab); output; if last.state then do; placefp='99999'; Areaname='Unincorporated '||upcase(stab); output; end; drop _: ; ***if status ne ' ' then put _all_; run; %macro filter; _ix=index(areaname,','); if _ix then areaname=substr(areaname,1,_ix-1); *--remove ", Missouri" (for example)--; %mend filter; options nomprint; libname sasctlgs clear; libname sasctlgs '/pub/sas/catalogs'; %genfmat(fmatname=place, arg=state placefp,arglen=7,labellen=64,savedoc=1, labelvar=areaname, setin=forfmat) *--test it--; data _null_; placefp='2900244'; put placefp= $place.; placefp='2900712'; put placefp= $place.; placefp='2958088'; put placefp= $place.; run;