x cd /pub/data/mable2k/Tools; %let pgm=gen_puma1eq; filename pgm "&pgm..sas"; *--Read the pums1 equivalency files and generate keyed sas datasets that can be used to look up the super puma code based on values of county, placefp, cousubfp for anywhere in the U.S. See tiger_codes108.sas for the job that accesses these datasets and uses them to add puma1 codes to mable2k. John Blodgett, July, 2003. --*; options ls=132; libname mable2k "/pub/data/mable2k"; libname pums2000 '/pub/data/pums2000'; libname user '/SAS_temp/user'; filename text '/pub/sas/formats/Spuma1eq.sas'; *<---we generate this format code that relates detailed geos to puma1 results; options fmtsearch=(pums2000 library work); x cd /pub/data/pums2000/zipfiles1 ; data _null_; file text; put 'Proc format library=pums2000.formats; ' / 'Value $puma1eq ' ; run; %macro doit(state,stab,names=1); %global statenm; %let statenm2=%sysfunc(translate(&statenm,%str(_),%str( ))); %let ustatenm=%upcase(&statenm); %let ustab=%upcase(&stab); data temp&state; filename in pipe "unzip -a -p all_&statenm2 PUMEQ1-&ustab..TXT"; infile in truncover; input sumLev $2-4 @; if sumlev in ('791','793','794'); if sumlev ne '791' then if _splitco; input +1 state $2. +1 puma1 $5. cnty $21-23 +1 cousubfp $5. +1 placefp $5. +3 tract6 $6. pop100 56-63 @64 areaname $char64.; if pop100 = . then do; put '***Invalid pop data -- check input statmt *** '/_all_; abort abend; end; if sumlev='791' then do; if scan(areaname,-1,' ')='(part)' then _splitco=1; else _splitco=0; retain _splitco; if not _splitco then output; return; end; if sumlev='793' and _splitco and scan(areaname,-1,' ') ne '(part)' then do; output; tract6='999999'; output; end; if sumlev='794' and _splitco then output; run; data _null_; set temp&state end=last; by puma1 state cnty sumlev notsorted; file text mod; retain tic "'" ticeqtic "'='" ticdashtic "'-'" nines '9999999999999999'; %*--we generate two kinds of entries for the format code: where a complete county is in the same puma1 we generate an interval with blanks for the cousub and place parts in the lower part and all nines in the upper part, e.g. '17001 '-'170019999999999'='17010' . When the county is split by the puma we generate intervals with the lower and upper limit codes filled in using the first. and last. checks. This only works because the data are sorted by cousbufp and placefp within the 793 records for a county and the 794 similarly with tract. --*; if sumlev='791' then put @3 tic $1. state $2. cnty $3. cousubfp $5. placefp $5. ticdashtic $3. state $2. cnty $3. nines $16. ticeqtic $3. puma1 $5. tic $1. ; else if sumlev='793' then put @3 tic $1. state $2. cnty $3. cousubfp $5. placefp $5. ticdashtic $3. state $2. cnty $3. cousubfp $5. placefp $5. '999999' tic ticeqtic $3. puma1 $5. tic $1. ' /* sumlev=793 */' ; else put @3 tic $1. state $2. cnty $3. cousubfp $5. placefp $5. tract6 $6. ticeqtic $3. puma1 $5. tic $1. ' /* sumlev= 794 */' ; run; %mend doit; options mprint; %dostates(01 25 29,names=1,msgs=1) %include text / source2; other=' '; ; *----test it------; data coded; set mable2k.alblks mable2k.mablks; length _arg $21 state $2; state=substr(county,1,2); if state in ('01' ) then cousubfp=' '; *<---in many states the cousubfp codes were not used--; _arg=county||cousubfp||placefp||compress(tract,'.'); length puma1 $5; puma1=put(_arg,$puma1eq.); if length(_arg) ne 21 then do; put _all_; stop; end; keep state county cousubfp placefp tract _arg puma1; run; proc freq data=coded; table state*puma1/list; run;