x cd /pub/data/acs2007/Tools; %let pgm=create_basetables; filename pgm "&pgm..sas"; *----Setup to read the 2 monster CSV files containing summary data (estimates and moes) for the entire country and turn them into a series of table-subset-based SAS base tables datasets. Coded by Billy Earney, OSEDA, with minor mods by jgb, November, 2008. Under contract with the Missouri Census Data Center. Revised to run with period parm, jgb 12-08. Can process 1-year or 3-year data based on parm specified. ----*; %let year=2007; %let period=1yr; %let period2=; %*--for 1-year estimates sometimes we need a null value instead of 1yr, like in data set names--; %let period=3yr; %let period2=3yr; libname acs "/pub/data/acs&year./"; libname basetbls "/pub/data/acs&year./basetbls"; libname user '/SAS_temp/userb'; filename estimate pipe "bunzip2 -c /pub/data/acs&year./basetbls/rawdata/basetables_estimates&period..csv.bz2"; filename moe pipe "bunzip2 -c /pub/data/acs&year./basetbls/rawdata/basetables_moes&period..csv.bz2"; options compress=binary; * compresses all the datasets; %macro asgnyrs; %if &period=%str(1yr) %then %do; Years="&year "; %end; %else %if &period=%str(3yr) %then %do; %let yearm2=%eval(&year - 2); Years="&yearm2.-&year"; %end; %else %if &period=%str(5yr) %then %do; %let yearm4=%eval(&year - 4); Years="&yearm4.-&year"; %end; %else %put ****asgnyrs does not work**** ; %mend asgnyrs; %let idvars=%str(Period SumLev -- cousubfp) ; /* =======================Begin comment================ data basetables_estimates&period2; Missing NULL N; length period $ 1 stab $ 2 state $ 2; infile estimate LRECL=200000 dsd termstr=crlf missover; period=substr("&period",1,1); *-----Read the data in using the INPUT statement as generated by the setup in .......................???-----; %include 'ivariable_list.sas'; if stab="US" then state=' '; else state=put(stab, $stabfip.); label period="Period in years of Survey (1, 3, or 5 years)"; *----Provide variables labels as generated by the setup in ..............................???---; %include 'ilabels.sas'; run; data basetables_moes&period2; Missing NULL N; length period $ 1 stab $ 3 state $ 2; infile moe LRECL=2000000 dsd termstr=crlf missover; period='1'; period=substr("&period",1,1); %include 'mvariable_list.sas'; if stab="US" then state=' '; else state=put(stab, $stabfip.); label period="Period in years of Survey (1, 3, or 5 years)"; %include 'mlabels.sas'; run; *---Try using indices instead of sorts because of space problems using sort---; proc datasets library=user nolist; modify basetables_estimates&period2 ; index create strecno=(state logrecno); modify basetables_moes&period2 ; index create strecno=(state logrecno); quit; ***proc sort data=basetables_estimates&period2; *** by state LogRecNo; ***run; ***proc sort data=basetables_moes&period2; *** by state LogRecNo; ***run; proc sort data=acs.allgeos&period2; by state LogRecNo; *---should not be necessary but wont hurt to be certain---; run cancel; %***let idvars2=%str(); data basetbls.ustabs00_07&period2.(keep= &idvars B00: B01: C01: B02: C02: B03: C03: B04: C04: B05: C05: B06: C06: B07: C07:) basetbls.ustabs08&period2.(keep=&idvars B08: C08:) basetbls.ustabs09_16&period2.(keep=&idvars B09: C09: B10: B11: C11: B12: C12: B13: C13: B14: C14: B15: C15: B16: C16:) basetbls.ustabs17_20&period2.(keep=&idvars B17: C17: B18: C18: B19: C19: B20: C20:) basetbls.ustabs21_24&period2.(keep=&idvars B21: C21: B22: C22: B23: C23: B24: C24:) basetbls.ustabs25_26&period2.(keep=&idvars B25: C25: B26: ); length Years $9; merge acs.allgeos&period2 (in=ingeos ) basetables_estimates&period2 (in=indata drop=B02003: B12007: ) ; by state LogRecNo; if not indata then do; put state= logrecno= geoid= areaname= ' ***Not found on data but was on geos data set****'; delete; end; *** if indata; if not ingeos then do; put /"***Logic Problem matching geos dataset*** " / stab= state= logrecno= indata= ingeos= ; abort abend; end; option mprint; %asgnyrs ; run; ======================End comment================== */ *---Now generate the parallel MOE-only data sets----; data basetbls.ustabs00_07_moes&period2.(keep= &idvars B00: B01: C01: B02: C02: B03: C03: B04: C04: B05: C05: B06: C06: B07: C07:) basetbls.ustabs08_moes&period2.(keep=&idvars B08: C08:) basetbls.ustabs09_16_moes&period2.(keep=&idvars B09: C09: B10: B11: C11: B12: C12: B13: C13: B14: C14: B15: C15: B16: C16:) basetbls.ustabs17_20_moes&period2.(keep=&idvars B17: C17: B18: C18: B19: C19: B20: C20:) basetbls.ustabs21_24_moes&period2.(keep=&idvars B21: C21: B22: C22: B23: C23: B24: C24:) basetbls.ustabs25_26_moes&period2.(keep=&idvars B25: C25: B26: ); length Years $9; merge acs.allgeos&period2 (in=ingeos ) basetables_moes&period2 (in=inmoes drop=B02003: B12007: ) ; by state LogRecNo; if inmoes; if not ingeos then do; put /"***Logic Problem moes not matching geos dataset*** " / stab= state= logrecno= inmoes= ingeos= ; abort abend; end; option mprint; %asgnyrs ; run; *----------now create indexes---------------; proc sql; create index state on basetbls.ustabs00_07&period2(state); create index state on basetbls.ustabs08&period2(state); create index state on basetbls.ustabs09_16&period2.(state); create index state on basetbls.ustabs17_20&period2.(state); create index state on basetbls.ustabs21_24&period2.(state); create index state on basetbls.ustabs25_26&period2.(state); create index state on basetbls.ustabs00_07_moes&period2.(state); create index state on basetbls.ustabs08_moes&period2.(state); create index state on basetbls.ustabs09_16_moes&period2.(state); create index state on basetbls.ustabs17_20_moes&period2.(state); create index state on basetbls.ustabs21_24_moes&period2.(state); create index state on basetbls.ustabs25_26_moes&period2.(state); create index geoid on basetbls.ustabs00_07&period2.(geoid); create index geoid on basetbls.ustabs08&period2.(geoid); create index geoid on basetbls.ustabs09_16&period2.(geoid); create index geoid on basetbls.ustabs17_20&period2.(geoid); create index geoid on basetbls.ustabs21_24&period2.(geoid); create index geoid on basetbls.ustabs25_26&period2.(geoid); create index geoid on basetbls.ustabs00_07_moes&period2.(geoid); create index geoid on basetbls.ustabs08_moes&period2.(geoid); create index geoid on basetbls.ustabs09_16_moes&period2.(geoid); create index geoid on basetbls.ustabs17_20_moes&period2.(geoid); create index geoid on basetbls.ustabs21_24_moes&period2.(geoid); create index geoid on basetbls.ustabs25_26_moes&period2.(geoid); quit;