x cd /pub/data/sf12010x/Tools; %let pgm=cnvt_sf12010xPR; 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 Aug 24, 2012. 0824-2012: This is cnvt_sf12010x.sas but for PR only. 7-7-14: edited to avoid using poptrends, blkrel10 data. ----*; %let temp=; *%let temp=%str(/temp); *<--used to control where data comes from and is stored depending on embargo status--; %global csvfiles; %let csvfiles=2; %*---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 for Puerto Rico"; %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; %let curtabno=0; %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 ; /*<=========================Comment out===================================== 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; ===========================End commented out================================ */ set sf12010.&stab.blocks(in=in2010); SumLev='101'; *---the value was 100 on the 2000 data set---; in2k=1; drop in2k; 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.-; /*<=========================Comment out===================================== 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; ===========================End commented out================================ */ set sf12010.&stab.bgs150; *** (in=in2010) poptrendsbg(in=in2k); 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','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; %dostates(72,names=1) ; *--we do not have the required blkrel10 sets to do the 2000 trends for PR yet--;