x cd /pub/data/pums2000/Tools; %let pgm=gen_valfmats; filename pgm "&pgm..sas"; *--Read the 2 PUMS Data Dictionary CSV files (exported from the Bureau xls spreadsheet) to generate the pums2000, File 1 value label SAS format source code modules. ***The output code generated here will be post-edited. This is just a shortcut starter set of code.*** John Blodgett, OSEDA, U. of Missouri Outreach & Extension Under a contract with the Missouri Census Data Center. May, 2003. --*; filename csvfiles '/pub/data/pums2000/pumsrec1*.csv'; filename codeout 'valfmats.sas'; *<--- source code for the pums value label format codes --; libname pums2000 '/pub/data/pums2000'; proc format; *--The pictca format is used for displaying values that fall within a topcoded range. It uses a comma7. format followed by the string "(tca)" indicating the number is a (state) topcode average. --; picture pictca 100-high='0,000,099 (tca)'; values; run; data values; infile csvfiles dsd missover; length rt $1; input rt @; _inline+1; if rt not in ('H','P') then do; input; *--release trailing @--; delete; end; length beg end len $4 AorN $1 name $32 label $96 lo hi $40 vallabel $96 comment $200; input beg -- comment; keep rt name AorN lo vallabel; *--To be a useful value label line we need a single non blank value (no intervals) with a non blank label and a variable that is not an allocation flag and one that is not a Yes/No code (a single $yesno can be used for all those). We also omit lines with super-categories, identified by ending with a colon. --; if lo ne ' ' and hi eq ' ' and (scan(label,-1,' ') ne 'Flag' or scan(label,-2) ne 'Allocation') and (name not =:'OCCSOC') and name not in('STATE','RECTYPE') and vallabel not in (' ','Topcode') and substr(vallabel,length(vallabel),1) ne ':'; if lo='blank' then if AorN='A' then lo=' '; else lo='.'; *--SAS needs to know the real value, not the pseudocode--; run; proc sort data=values; by rt name lo; run; data _null_; set values ; by rt name; file codeout; if first.rt then put / '****Begin value formats for variables on the ' rt $1. ' file***; ' /; retain tic "'" ticeqtic "'='"; ; if first.name then do; length _char 8; _char= (AorN = 'A'); retain _char; if _char then _s='$'; put 'Value ' _s name ; end; if index(vallabel,tic) then vallabel=translate(vallabel,' ',tic); if _char then put +4 tic $1. lo +(-1) ticeqtic $3. vallabel tic ; else do; if substr(lo,length(lo),1)='+' then do; *--top-coded interval, so point it to the special pictca PICTURE format--; length _line $80; _line=scan(lo,1,'+')||'-high=[pictca.];'; put +4 _line ; end; else put +4 lo '=' tic $1. vallabel tic ; end; if last.name then put +4 ';'; run;