x cd /pub/data/pums2000/Tools; %let pgm=gen_cnvtcode1; filename pgm "&pgm..sas"; *--Read the 2 PUMS Data Dictionary CSV files (exported from the Bureau xls spreadsheet) to generate the pums2000, File 1 conversion code. John Blodgett, OSEDA, U. of Missouri Outreach & Extension Under a contract with the Missouri Census Data Center. March, 2003. --*; filename csvfiles '/pub/data/pums2000/pumsrec1*.csv'; filename codeouth 'read_pums1h.sas'; *<--- generates the sas code (attrib and input stmts) to read the housing data files; filename codeoutp 'read_pums1p.sas'; *<--- generates the sas code (attrib and input stmts) to read the person data files; libname pums2000 '/pub/data/pums2000'; libname user '/SAS_temp/user'; data all; 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 $80 lo hi $40 vallabel $80 comment $200; input beg -- comment; if _n_ le 10 then put _all_; drop lo hi vallabel; *--for now we are not going to use the value labels---; if beg ne lag(beg); *--i.e., we only want the first line for a field/variable--; run; proc sort; by rt _inline ; run; data _null_; set all; by rt; if rt='H' then file codeouth; else file codeoutp; length typelen $4 _input $2000; retain _input; *<---string where we generate most of the input stmt to read the current record type--; if upcase(AorN)='N' then do; if len le '6' then nlen='4'; else nlen='8'; typelen=nlen; end; else typelen='$'||len; label=compress(label,"'"); *--remove any single quotes from label--; put 'Attrib ' name +1 "length=" typelen " label='" label "';"; _input=trim(_input)|| ' '|| trim(name); if beg=end then _input=trim(_input)||' '||beg; else _input=trim(_input)||' ' ||trim(beg)||'-'||trim(end); *--add the name and col specs to input. Because we previously have declared variables type with the attrib stmt we do not need to specify the "$" in the column specs.--; _nvars +1; if _nvars=6 then do; _nvars=0; _input=trim(_input)||'/'; *--we break up the input statement into multiple lines for ease of reading and editing--; end; if last.rt then do; *---add the input statement at the end of the current code file---; put 'input '; _line=scan(_input,1,'/'); _nline=1; do while(_line ne ' '); put @3 _line ; _nline+1; _line=scan(_input,_nline,'/'); end; put '; *--end of input statement to read file ' rt ';'; _input=' '; *--blank it out after writing the h input stmt to prepare it for the P variable specs--; end; run;