x cd /pub/data/acspums; %let pgm=puma2k_puma10; filename pgm "&pgm..sas"; *---Read the equivalency file generated using mable14 relating the old 2k PUMAs to the new "2010" (aka "2012") PUMAs. We then generate a permanent format code that we can use to do lookups to assign puma10 values when there is a 2k PUMA which is entirely (or mostly - we used a 98% cutoff) within a 2010 PUMA. See our acs20123yr.sas run, for example.-; title "&pgm.: Generate Equivalency File & Format Code Linking PUMAs"; libname acspums '/pub/data/acspums'; filename csvin "/pub/data/acspums/puma2k_puma12.csv"; data acspums.puma2k_puma12(label='Equivalency between old (2k) and new (2012) PUMAs' ); infile csvin dsd dlm='09'x missover firstobs=3; length State $2 puma2k puma12 $5 pop10 4 afact afact2 4; format afact afact2 5.3 ; input state -- afact2; attrib EQflag length=3 label='PUMAs Equivlaent?'; EQflag=(afact ge .98) and (afact2 ge .98); *---has to be a 1-to-1 equivalency---; run; proc print data=acspums.puma2k_puma12 (obs=50); by state; id puma2k; title2 "&syslast"; run; proc sort data=acspums.puma2k_puma12 out=temp; by state puma2k descending pop10; run; data temp2; set temp; by state puma2k; if first.puma2k; run; proc freq data=temp2; table state*EQflag; format state $state.; run; *---now generate the format code to be used as a lookup table for linking puma2k and puma12 codes when equivalent--; data fmtin; set acspums.puma2k_puma12; where EQflag; keep state puma2k puma12; run; filename text '/pub/sas/formats/Spma2k12.sas'; libname sascats '/pub/sas/catalogs'; *--We reallocate it to get write access--*; %genfmat (sasin=fmtin,argvars=state puma2k,arglen=7,labelvar=puma12,labellen=5, other=%str(-0009),fmatlib=sascats,fmatname=pma2k12_) ; *----The macro will use the rows/obs in the input set to generate both a sas code file with defn of the format code $pma2k12 and the corresponding code as a member of our permanet formats catalog.-; options fmtsearch=(sascats); data _null_; *---test the format code---; set acspums.puma2k_puma12 (obs=50); length _puma12 $5 _arg $7; _arg=state||puma2k; _puma12=put(_arg,$pma2k12_.); put state= puma2k= _puma12=; run;