x cd /pub/data/sf12010x/Tools; %let pgm=cnvt_sf12010x; filename pgm "&pgm..sas"; *----Create a series of standard extract data sets for one or more specified state using standard census geographies. jgb, OSEDA, MCDC . Begin coding June 22, 2011. 08-15-11: Adding steps to generate CSV files with trends data for export to mcdc side and profiles. 08-31-11: Rerunning all conversions after fix to Chinese and OtherAsian variables. 12-12-11: We created setup cnvt_sf12010x_special.sas to generate more datasets of this filetype. 02-27-12: We modified code back in December to add geocodes to XXblocks data set but it never got run. Until now. ----*; %let temp=; *%let temp=%str(/temp); *<--used to control where data comes from and is stored depending on embargo status--; %global csvfiles; %let csvfiles=0; %*---Has 3 values: 0 means no CSV files be generated. 1 means only CSV files, no conversion. and 2 meaning do conversions AND CSV files . ----; %let csvfiles=0; *--for the rerun 2/12 to add geos to the blocks dataset--; %let blocksonly=0; *--new global flag to specify that you only want to convert the block level sets. Set to 0 normally---; libname sf12010 "/pub/data/sf12010&temp" access=readonly; libname sf1 (sf12010); *--alternate libref--; libname sf12010x '/pub/data/sf12010x'; libname sf1x (sf12010x); *--alternate libref--; libname sf1x2k '/pub/data/sf12000x' access=readonly; libname blkrel10 '/pub/data/blkrel10' access=readonly; %global temp; *--set this parm to a value of %str(/temp) when reading and writing from the temp subdir (embargoed)-; %let moe_default=; %let dvmode=data; %*--the "dovar mode" global parm controls what kind of output is generated by the dovar macro. The values are data or meta, which cause it to either generate actual conversion data step code or code to create metadata set Variables. The value is also looked at by smaller macros which generate the start and end of the data steps during which the dovar macro invocations take place. --*; title "&pgm: Create sf12010x Extract Datasets from sf12010 Datasets"; %global pctflag; *---used by invoke_dovars to conditionally generate code depending on whehter PCT tables are available for the level; %global pctof table curtable curtabno dvmode; /* ========================begin comment==================================== ==========================end comment====================================== */ %let curtabno=0; %let dvmode=meta; *------Here is the data step that generate sf3x.Variables when dvmode=meta-----------; *-----meta processing-----------------------------; data sf1x.Variables(label="Meta data describing the variables on these datasets"); attrib Name label='Variable Name' length=$32 Label length=$80 format=$char. Definition length=$200 label='Definition - Code used to derive' Comment length=$400 Format length=$16 TypeLen length=$8 label='Variable type and length' Universe length=$64 UnivVar length=$32 label='Universe Variable' WtVar length=$32 label='Weight Variable' Lvl length=3 label="Data Indent Level" Display length=3 label="Display in std report?" PctFlag length=3 label='Pct Variable Flag' Table length=$64 TableNo length=3 label='Table #' Keywords length=$80 Year length=$4 Source length=$40 RefTables length=$40 label='Related Table(s)' ; retain Year '2010'; retain Source 'Summary File 1, 2010 Census'; %include 'invoke_dovars.sas' / source2; run; options nonumber nodate orientation=landscape nocenter; ods pdf file="../Variables.pdf" ; ****orient=landscape; ods html file='../Variables.html' style=osedablue; ods listing close; proc print data=sf1x.Variables label; where pctflag=0 or UnivVar=' '; *<--do not show the Pct variables unless they are stand-alone--; by table notsorted universe notsorted; id name; var label--comment UnivVar WtVar; format label $char.; title 'Metadata for the sf12010x Filetype (Partial listing of Variables dataset)'; footnote 'Note: Universe Variable is denominator used to create corresponding Pct Variable'; title2 "Revised as of &sysdate &systime"; run; ods pdf close; ods html close; *==========================================================================================*; %let dvmode=data; %let curtabno=0; %macro doit(state,stab); %let ustab=%upcase(&stab); %let pctflag=0; %if &csvfiles = 1 %then %goto csvblks; %***goto bgs; %*---while debugging this is an easy way to skip already-test portions of the code-----; %*----do the block level data set----*; proc sort data= blkrel10.&stab.poptrend2010blks(rename=(blk=block) drop=totpop tothus) out=poptrends; by county cousubfp placefp tract block; run; data sf1x.&stab.blocks (label="Census Block summaries for &statenm" index=(county) compress=Yes); length SumLev $3 esriid $16 areaname $10 ; merge sf12010.&stab.blocks(in=in2010) poptrends(in=in2k); * blkrel10.&stab.poptrend2010blks(in=in2k rename=(blk=block)); by county cousubfp placefp tract block; if in2010; SumLev='101'; *---the value was 100 on the 2000 data set---; if not in2k then do; _notmatched+1; if _notmatched gt 1250 then abort abend; end; if landsqmi=. then do; LandSQMI=AreaLand/2589988; AreaSQMI=LandSQMI + (AreaWatr/2589988); format LandSQMI AreaSQMI 9.2; end; %include 'invoke_dovars.sas'/NOsource2; %*<----this module does the work of assigning the global parms and invoking the dovars parm for each variable on the dataset. Which means this module does not really define what sf12010x is, it is this included module that really does it. ----; keep esriid geocode sumlev areaname logrecno state stab lsadc county tract bg block cbsa csa metdiv ua placefp cousubfp ; *--following line to keep more geos at block level added 9-8-11---; keep necta nectadiv cd111 sldu sldl vtd zcta5 sdelm sdsec sduni; keep IntPtLon IntPtLat AreaSQMI LandSQMI ; keep TotPop -- AvgSizeRenter; %if &pctflag=0 %then %do; drop hawaiian--PctOtherAsian mexican--PctOtherHispanic unmarriedPartner--PctUnmarriedPartner unmPartnerHHs--PctSameSexPrtnrHHs ; %end; drop _: ; run; %csvblks: %if &csvfiles ne 0 %then %do; data blktrends; set sf1x.&stab.blocks(keep=logrecno sumlev stab geocode TotPop00 popchange where=(totpop00 ne .)); geocode=compress(geocode,'-.'); run; filename dlmout "/pub/data/temp/sf1xblktrends&stab..csv"; %cnvtdlm( lrecl=512,names=1,quotes=0) run; %end; %bgs: %if &blocksonly %then %goto endmac; %*<======================new, 2-27-12---; %if &csvfiles = 1 %then %goto csvbgs; %***goto selectedinv; %*----do the block-group (150 sumlev) level data set----*; proc sort data= blkrel10.&stab.poptrend2010bgtrcopl(where=(sumlev='150') keep=county sumlev tract bg totpop2k) out=poptrendsbg; by county tract bg; run; data sf1x.&stab.bgs150 (label="BG level (150) summaries for &statenm" compress=Yes index=(county)); length SumLev $3 esriid $16 areaname $14; *<---this length was 10 prior to 8-4-11 causing truncation. Need to rerun.-; merge sf12010.&stab.bgs150(in=in2010) poptrendsbg(in=in2k); by county tract bg; if in2010; if not in2k then do; _notmatched+1; if _notmatched gt 1250 then abort abend; end; if landsqmi=. then do; LandSQMI=AreaLand/2589988; AreaSQMI=LandSQMI + (AreaWatr/2589988); format LandSQMI AreaSQMI 9.2; end; %include 'invoke_dovars.sas'/NOsource2; %*<----this module does the work of assigning the global parms and invoking the dovars parm for each variable on the dataset. Which means this module does not really define what sf12010x is, it is this included module that really does it. ----; keep esriid geocode sumlev areaname logrecno state stab lsadc county tract bg cbsa csa metdiv ua ; keep IntPtLon IntPtLat AreaSQMI LandSQMI ; keep TotPop -- AvgSizeRenter; %if &pctflag=0 %then %do; drop hawaiian--PctOtherAsian mexican--PctOtherHispanic unmarriedPartner--PctUnmarriedPartner unmPartnerHHs--PctSameSexPrtnrHHs ; %end; drop _: ; run; %csvbgs: %if &csvfiles ne 0 %then %do; data bgtrends; set sf1x.&stab.bgs150(keep=logrecno sumlev stab geocode TotPop00 popchange where=(totpop00 ne .)); geocode=compress(geocode,'-.'); run; filename dlmout "/pub/data/temp/sf1xbgtrends&stab..csv"; %cnvtdlm( lrecl=512,names=1,quotes=0) run; %end; %selectedinv: %if &csvfiles = 1 %then %goto csvinv; %let pctflag=1; %let invlevls=%str('040','050','060','140','155','160','320','420', '500','610','620','860','871','950','960','970'); %*----do the selected inventory levels data set----*; data poptrendsinv; *---We grab 2000 sf1 counts for everything excepts tracts (and blocks and bgs, above)--; set sf1x2k.us(where=(state="&state" and sumlev in (&invlevls)) keep=SumLev esriid Areaname geocomp County placefp cousubfp TotPop state rename=(TotPop=TotPop2k areaname=_areaname2k) in=insf1) blkrel10.&stab.poptrend2010bgtrcopl(where=(sumlev='140') drop=bg TotPop TotHUs stab in=intracts ) ; if geocomp gt '00' then delete; if intracts then esriid=county||compress(tract,'.'); if sumlev='860' then do; if substr(esriid,4,2)='HH' then delete; esriid=state||esriid; SumLev='871'; end; drop geocomp tract placefp cousubfp; run; proc sort; by sumlev esriid; run; proc sort data=sf12010.&stab.inventory(where=(sumlev in (&invlevls) and geocomp='00')) out=sf1invdata; by sumlev esriid; run; data sf1x.&stab.selectedinv(label="Selected inventory summaries for &statenm" index=(sumlev) compress=Yes); length SumLev $3 esriid $16; merge sf1invdata(in=in2010) poptrendsinv(in=in2k); by sumlev esriid; if not in2010 and (placefp ne '99999' and not (substr(esriid,4,2) in ('XX','HH') )) then put sumlev= esriid= _areaname2k= " ***NOT in sf1 2010 data ?? ****"; if first.sumlev then do; _notmatched=0; _matched=0; end; if in2010 and not in2k then do; _notmatched+1; if last.sumlev and substr(sumlev,1,1) ne '6' and substr(sumlev,1,1) ne '9' and (_notmatched gt 100 or _matched < _notmatched) then do; file log; put '**missing > 100 geos from 2k census (or more than half) : ' state= sumlev= _notmatched= _matched=; end; *** abort abend; end; if in2010; if in2k then _matched+1; %include 'invoke_dovars.sas'/source2; keep esriid geocode sumlev areaname logrecno state stab lsadc county tract cousubfp placefp zcta5 ua cbsa metdiv csa metdiv; keep IntPtLon IntPtLat AreaSQMI LandSQMI ; keep TotPop -- AvgSizeRenter; %if &pctflag=0 %then %do; drop hawaiian--PctOtherAsian mexican--PctOtherHispanic unmarriedPartner--PctUnmarriedPartner unmPartnerHHs--PctSameSexPrtnrHHs ; %end; drop _: ; run; %csvinv: data invtrends; set sf1x.&stab.selectedinv(keep=logrecno sumlev stab geocode TotPop00 popchange where=(totpop00 ne .)); geocode=compress(geocode,'-.'); run; %if &csvfiles ne 0 %then %do; filename dlmout "/pub/data/temp/sf1xinvtrends&stab..csv"; %cnvtdlm( lrecl=512,names=0,quotes=0) run; %end; %endmac: %mend doit; options NOmprint; *---run 8-18-11 to generate CSV files for all states---; /* ========================begin comment==================================== %dostates(10,names=1); %dostates(16 29 39 49 54 55,names=1); %dostates(13 21 23 33 51,names=1); %dostates(04 27,names=1); %dostates(30 36 40 50,names=1); %dostates(02 08 09 31 37,names=1); %dostates(06 20 42 56,names=1) ; %dostates(01 15,names=1) %dostates(17 18 32 41 46 53,names=1); %dostates(05 22 19 34 48,names=1); %dostates(11 12 25 26 45,names=1); %dostates(24,names=1); %dostates(28 35 38 44 47,names=1) %***dostates(72,names=1) ; *--we do not have the required blkrel10 sets to do the 2000 trends for PR yet--; ==========================end comment====================================== */ %dostates(n=51,names=1); /* ========================begin comment==================================== *---Ran this step interactively on 9-8-11. Then manually renamed usregdivNEW to be usregdiv.-------; data sf1x.usregdivNEW; if 0 then set sf1x.wyselectedinv(keep=sumlev geocode areaname esriid state stab _numeric_); *--establish formats-; set sf1x.usregdiv; esriid=geocode; run; ==========================end comment====================================== */