x cd /pub/data/pums2000/Tools; %let pgm=nan_Valfmats; filename pgm "&pgm..sas"; *----Generate the pums2000 value label formats. Using input from xls files provided by the Census Bureau via Roy Williams, MISER. John Blodgett, OSEDA, U. of Missouri Outreach & Extension Under contract with the Missouri Census Data Center. Oct. 2003 ----*; title "&pgm : Generate Value Labels Dataset and SAS Formats"; filename inp "pumsrecdiffsp.csv" ; *---input files from R. Williams, Mass. SDC. Here we have basic variable data, including value labels for most (but not all) variables. The value labels for some of the "long lists" have to be handeled separately----*; filename inh "pumsrecdiffsh.csv" ; filename in3 ('5%_pums_ancs_note.csv','5%_pums_lang_note.csv'); libname pums2000 '/pub/data/pums2000'; libname user '/SAS_temp/user'; title "&pgm: Generate pums2000 Values Labels metadata set and SAS Format Modules"; *---There are two separate files: 1 for the H recs and 1 for the P recs. We run the same program for reading each. --; %macro dofile(rt); data &rt; infile in&rt dsd missover lrecl =4000 firstobs=7; length rt $1 beg end $3 len $2 an $1 varname $8 varlabel $96 dum1-dum4 $1 code5 code5high $8 label5 $96 code1 code1high $8 label1 $96 note $96; input rt -- note; if rt ne ' '; if index(varlabel,'Allocation Flag')=0; *--skip these--; fmtname=varname; if code1 ne ' ' and code1high=' ' then do; codeval=code1; vallabel=label1; if code5=code1 and code5high=' ' and label1=label5 then do; sample='b'; output; end; else do; *---its a 1 pct sample value only--; sample='1'; output; if code5 ne ' ' and code5high=' ' then do; sample='5'; codeval=code5; vallabel=label5; output; end; end; end; else if code5 ne ' ' and code5high=' ' then do; *---its a 5 pct sample value only--; codeval=code5; vallabel=label5; sample='5'; output; return; end; else delete; keep rt varname codeval vallabel fmtname sample; run; proc sort; by rt varname codeval; run; proc print data=&rt (obs=30); by fmtname notsorted; id fmtname; title2 "Partial listing if &rt"; run; %mend dofile; %dofile(p); %dofile(h); *---Step 2: Process the "long list" format codes (these were not in the Bureau codebook, but instead had to be gleaned from special Appendix files/spreadsheets) - 1 pct sample------*; proc format library=pums2000.formats1 cntlout=step2outf(keep=fmtname start label rename=(start=codeval label=vallabel) ); select $ancst1_ $lang1_; run; proc sort; by fmtname; run; proc print data=step2outf(obs=30); Title ' '; Title '1% Data - step2outf'; run; *---Step 3: Similar to what we did in step 2, but now reading xls-derived CSV ,files for the 5 pct sample---*; data step3outf; infile in3 eov=_eov dlm =',' dsd lrecl=2000 truncover firstobs=5; length fmtname $8 codeVal $ 8 ValLabel $ 36 Note $ 600; input codeVal $ ValLabel $ Note $ ; retain filenum 1 fmtname 'Ancst5_'; if _eov then do; _eov=0; filenum+1; select(filenum); *when (1) fmtname='A'; when (2) fmtname='Lang5_'; otherwise fmtname='O'; end; put _infile_ filenum= fmtname=; input //; put _infile_ ' 3 records flushed***'; delete; end; keep fmtname codeval vallabel note; run; proc sort; by fmtname; run; proc print data=step3outf(obs=30); Title '5% Data - step3outf'; run; *---3b: combine the two "large" value label sets and add Varname, rt and sample variables---; data with_varnames; length varname $8 rt $1; set step2outf(in=in1) step3outf(in=in5); by fmtname ; retain _vars ' '; fmtname=upcase(fmtname); if first.fmtname then select(fmtname); when('ANCST1_') _vars='ancfrst1 ancscnd1'; when('ANCST5_') _vars='ancfrst5 ancscnd5'; when('LANG1_') _vars='lang1'; when('LANG5_') _vars='lang5'; otherwise do; put "Logic Problem: fmtname not allowed for in Step 4**************************" fmtname=; abort ; end; end; if in1 then sample='1'; else sample='5'; _i=1; varname=scan(_vars,1); do until(varname=' '); if _varname in(' ') then rt='H'; else rt='P'; output; _i+1; varname=scan(_vars,_i); end; drop _:; run; proc sort data=with_varnames; by rt varname codeval; run; *----------------Step 4: Merge them all-------------*; data pums2000.varvals(compress=yes label='Variable Code Values: combined 1 and 5 pct samples'); length sample rt $1 ; merge H (in=inH ) P (in=inP ) with_varnames(in=in3); by rt varname codeVal; if length(fmtname) gt 7 then fmtname=substr(fmtname,1,5)||substr(fmtname,length(fmtname),1)||'_'; else if index('123456789',trim(substr(fmtname,length(fmtname),1))) then fmtname=trim(fmtname)||'_'; run;