filename pgm "P:\mcdc\acsdocs\read_table_shells2005.sas"; *---read the table shells excel spreadsheet using code provided by Dan Keating, Washington Post, 8/06. We upload the resulting SAS dataset to mcdc where it will be used. jgb, 8-12-06. 8-31-06 We also read the comparable spreadsheet for Wave 2 tables released Aug 29 to create the datasets tablevars2 and tables2, uploaded to Unix machihe, mcdc.missouri.edu. The August29 tableshells spredsheet was downloaded from Bureau ftp site. 9-28-06 Process the Wave 3 tables as released (embargoed) yesterday. Creates tablevars3 and tables3 datasets, etc. ---; *<====see edit_tablevars.sas for job that does some formatting and editing of these datasets====; /* <====================comment out steps for Wave 1 and Wave 2 tables======================= PROC IMPORT OUT= WORK.temp DATAFILE= "p:\john\attachments\ACS_2005_August15_tableshells.xls" DBMS=EXCEL REPLACE; SHEET="Sheet1$"; GETNAMES=YES; MIXED=NO; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN; *---fix the problem with 3 rows on in xls files not being read correctly.----; data tempedit; set temp; if table_id='C04004' and line_number=. then do; if left(stub)='Italian' then line_number=16; if left(stub)='Lithuanian' then line_number=17; put / _all_; end; *----we also discovered this title problem which we manually fix----; if table_id='B03002' and stub='z' then stub="HISPANIC OR LATINO ORIGIN BY RACE"; run; data tablevars(drop=table_title table_universe nlines) tables(keep=table_ID table_title table_universe nlines); length Table_Id $9 Line_Number 3 Stub $208 lineflg 3; length Table_Title $400 Table_Universe $208; set work.tempedit(drop=estimate margin_of_error ); where table_id ne ' '; where also line_number=round(line_number); *<--- filters the .5 and 3.5 line #s--; label lineflg='Value of 1 indicates line_number edited'; by table_id notsorted; retain table_title table_universe; if first.table_id then do; table_title=left(stub); nlines=0; return; end; else if line_number=. then do; *--verify its a universe line---; stub=left(stub); if stub=:'Universe:' then do; table_universe=left(substr(stub,11)); return; end; else do; *--assume it is a continuation of the title---; table_title=trim(table_title)||' '||left(stub); return; end; end; Lineflg=0; nlines+1; if line_number=nlines then output tablevars; else do; put '***WARNING: Line number field not as expected. Will replace with counter.*** ' / _all_; line_number=nlines; Lineflg=1; output tablevars; end; if last.table_id then output tables; run; proc sort data=tables; by table_id; run; proc sort data=tablevars; by table_id line_number; run; signon mcdc; rsubmit; libname acs '/pub/data/acs2005'; filename pgmout '/pub/data/acs2005/Tools/read_table_shells2005.sas'; proc upload data=tablevars out=acs.tablevars; proc upload data=tables out=acs.tables; proc upload infile=pgm outfile=pgmout; *<---upload this program to Tools lib--; run; endrsubmit; *=============================Wave 2=========================================*; PROC IMPORT OUT= WORK.temp DATAFILE= "p:\mcdc\acsdocs\ACS_2005_August29_tableshells.xls" DBMS=EXCEL REPLACE; SHEET="Sheet1$"; GETNAMES=YES; MIXED=NO; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN; *---fix the problem with 3 rows on in xls files not being read correctly.----; data tempedit; set temp; *---these edits were for wave 1 and will not be relevant for this run. We leave them here as a template/example of how to edit if we find problems.-; if table_id='C04004' and line_number=. then do; if left(stub)='Italian' then line_number=16; if left(stub)='Lithuanian' then line_number=17; put / _all_; end; *----we also discovered this title problem which we manually fix----; if table_id='B03002' and stub='z' then stub="HISPANIC OR LATINO ORIGIN BY RACE"; run; data tablevars(drop=table_title table_universe nlines) tables(keep=wave table_ID table_title table_universe nlines); length Table_Id $9 Line_Number 3 Stub $208 lineflg 3 Wave $1; length Table_Title $400 Table_Universe $208; set work.tempedit(drop=estimate margin_of_error ); retain wave '2'; *<-----This set of economic tables dubbed "Wave 2" by Bureau--; where table_id ne ' '; where also line_number=round(line_number); *<--- filters the .5 and 3.5 line #s--; label lineflg='Value of 1 indicates line_number edited'; by table_id notsorted; retain table_title table_universe; if first.table_id then do; table_title=left(stub); nlines=0; return; end; else if line_number=. then do; *--verify its a universe line---; stub=left(stub); if stub=:'Universe:' then do; table_universe=left(substr(stub,11)); return; end; else do; *--assume it is a continuation of the title---; table_title=trim(table_title)||' '||left(stub); return; end; end; Lineflg=0; nlines+1; if line_number=nlines then output tablevars; else do; put '***WARNING: Line number field not as expected. Will replace with counter.*** ' / _all_; line_number=nlines; Lineflg=1; output tablevars; end; if last.table_id then output tables; run; proc sort data=tables out=tables2; by table_id; run; proc sort data=tablevars out=tablevars2; by table_id line_number; run; signon mcdc; rsubmit; libname acs '/pub/data/acs2005'; filename pgmout '/pub/data/acs2005/Tools/read_table_shells2005.sas'; proc upload data=tablevars2 out=acs.tablevars2; proc upload data=tables2 out=acs.tables2; proc upload infile=pgm outfile=pgmout; *<---upload this program to Tools lib--; run; endrsubmit; ===============================end comment========================== */ *=============================Wave 3=========================================*; PROC IMPORT OUT= WORK.temp DATAFILE= "p:\mcdc\acsdocs\ACS_2005_October3_tableshells.xls" DBMS=EXCEL REPLACE; SHEET="Sheet1$"; GETNAMES=YES; MIXED=NO; SCANTEXT=YES; USEDATE=YES; SCANTIME=YES; RUN; *---fix the problem with 3 rows on in xls files not being read correctly.----; data tempedit; set temp; *---no fixes yet--; run; data tablevars(drop=table_title table_universe nlines) tables(keep=wave table_ID table_title table_universe nlines); length Table_Id $9 Line_Number 3 Stub $208 lineflg 3 Wave $1; length Table_Title $400 Table_Universe $208; set work.tempedit(drop=estimate margin_of_error ); retain wave '3'; *<-----This set of economic tables dubbed "Wave 3" by Bureau--; where table_id ne ' '; where also line_number=round(line_number); *<--- filters the .5 and 3.5 line #s--; label lineflg='Value of 1 indicates line_number edited'; by table_id notsorted; retain table_title table_universe; if first.table_id then do; table_title=left(stub); nlines=0; return; end; else if line_number=. then do; *--verify its a universe line---; stub=left(stub); if stub=:'Universe:' then do; table_universe=left(substr(stub,11)); return; end; else do; *--assume it is a continuation of the title---; table_title=trim(table_title)||' '||left(stub); return; end; end; Lineflg=0; nlines+1; if line_number=nlines then output tablevars; else do; put '***WARNING: Line number field not as expected. Will replace with counter.*** ' / _all_; line_number=nlines; Lineflg=1; output tablevars; end; if last.table_id then output tables; run; proc sort data=tables out=tables3; by table_id; run; proc sort data=tablevars out=tablevars3; by table_id line_number; run; signon mcdc; rsubmit; libname acs '/pub/data/acs2005'; filename pgmout '/pub/data/acs2005/Tools/read_table_shells2005.sas'; proc upload data=tablevars3 out=acs.tablevars3; proc upload data=tables3 out=acs.tables3; proc upload infile=pgm outfile=pgmout; *<---upload this program to Tools lib--; run; endrsubmit;