x cd /pub/data/sf12000x/Tools; %let pgm=cnvt_mo; filename pgm "&pgm..sas"; *----Create sf12000x.moi, sf12000x.moblks and sf12000.moh from sf12000 data sets plus stf901x2 sets. Note that we get the 1990 pop counts from the 1990 moblks00, mobgs00 and motrs00 data sets in stf901x2. Earlier we just used the data for these levels as they were reported with 1990 geocodes but that was very unsatisfactory. J. Blodgett, 8-13-01. We replace earlier version that referenced 1990 tract and bg data with their 1990 geocodes. We have since created versions in stf901x2 that have the data reaggregated to the 2000 geography. Rerun, Apr. 9, 2002: Adding grcid id variable and creating sf1x.mostcnty view. Also had to modify to reflect restructuring of input sf1 datasets. ----*; options msglevel=i fullstimer; *--trying to get a handle on what is taking so long-----; libname sf12000 '/pub/data/census_2000/sf12000' access=readonly; libname sf1 (sf12000); *--alternate libref--; libname sf12000x '/pub/data/sf12000x'; libname sf1x (sf12000x); *--alternate libref--; %libname(sf1prof); %libname(stf901x2,opts=); *<---custom generated 1990 stf1 extract set ready to be merged with our sf2000x data set-; libname user '/SAS_temp/user'; /*<=========================Comment out===================================== *---preliminary step: Create indices on geo_id for the stf901x2.motrs00 and mobgs00 data sets to facilitate grabbing those 1990 pop counts during the merge step---; proc datasets library = stf901x2; modify moblks00; index create geo_id /unique; modify motrs00; index create geo_id /unique; modify mobgs00; index create geo_id /unique; quit; ===========================End commented out================================ */ data ph_pct/view=ph_pct; merge sf1.moph sf1.mopct(drop=geocode--areasqmi); by geo_id; run; data _2000moi sf1x.moh(index=(county) label='Mo Hierarchal level summaries' compress=yes) sf1x.moblks(index=(county) drop=areaname geocomp label='Mo block level summaries' compress=yes) ; length default=5; length geo_id 5 esriid $42. grcid $40; set ph_pct sf1.mophblks(in=inblks) end=last; if geocomp='00' ; *<-------------Note this filter--------------------; format county $mocnty.; if inblks then do; geocode=%concatd(county,tract,block); esriid=county||trim(compress(tract,'.'))||block; end; %include sascode(sf12000x); *--gets code in /pub/sascode/sf12000x.sas---; if esriid=:'29' then grcid=substr(esriid,3); else grcid=esriid; *<--GRC does not keep MO state code on poly ids-; *--keep list here is for ids only. Variables totpop -- year are kept as part of included code--; TotPop90=.; if sumlev='101' then do; set stf901x2.moblks00(keep=geo_id totpop rename=(totpop=TotPop90)) key=geo_id; if _iorc_ then do; _noblk90+1; drop _noblk90; if _noblk90 le 30 then put 'No 90 pop count for this block (assuming 0):' geocode=; totpop90=0; _error_=0; *--live with it--; end; change=totpop - totpop90; if totpop90 then pctchange=100*change/totpop90; output sf1x.moblks; end; else if sumlev in ('040','050','060','140','150','155','160','390','395','500','871','881') then output _2000moi; else if sumlev in ('070','080','091','158') then output sf1x.moh; else delete; *<--not necessary, but for emphasis--; if last then put _noblk90 ' blocks had missing 1990 pop counts***************'; keep sumlev geo_id geocode geocomp state stab areaname county tract bg block cousubfp placefp zcta5 areasqmi landsqmi intptlon intptlat esriid grcid; run; proc sort data =_2000moi; by sumlev geocode; run; %let keep90= %str(keep=sumlev geocode totpop rename=(totpop=totpop90) ); *<============NOTE: This section of code may need to be edited per the specific geographic area being converted==; options msglevel=i; data sf1x.moi(index=(sumlev)); merge _2000moi(in=in2k) stf901x2.moi ( &keep90 in=in90i label='Mo Inventory Summaries'); by sumlev geocode; if in2k; if not in90i then totpop90=.; *--Initialize to missing if not in the moi 1990 set-; if sumlev='140' then do; set stf901x2.motrs00(keep=geo_id totpop rename=(totpop=totpop90)) key = geo_id; if _iorc_ then do; _notr90+1; drop _notr90; if _notr90 le 30 then put 'No 90 pop count for this tract (assuming 0):' geocode=; totpop90=0; _error_=0; *--live with it--; end; end; else if sumlev='150' then do; set stf901x2.mobgs00(keep=geo_id totpop rename=(totpop=totpop90)) key = geo_id; if _iorc_ then do; _nobg90+1; drop _nobg90; if _nobg90 le 30 then put 'No 90 pop count for this bg (assuming 0):' geocode=; totpop90=0; _error_=0; *--live with it--; end; end; *if in90i then do; if totpop90 ne . then do; change=totpop - totpop90; if totpop90 then pctchange=100*change/totpop90; end; run; *<-----------------This step being added to setup 10-5-01, jgb: we created 2 separate sets, mozips and mozipcos with the data for complete zctas and zctas within counties, including good 1990 pop counts derived by retabulating the 90 data for the 2000 zcta geography. But now we want to use those values to UPDATE the moi set here. We have redundant copies of these data which is bad but sometimes convenient-------------; data zpops90; set sf1x.mozips (keep=sumlev geocode totpop90 change pctchange ) sf1x.mozipcos(keep=sumlev geocode totpop90 change pctchange ); by sumlev geocode; run; *---Once we verify that this works we rerun it just once with moitemp replace with moi-----------; data sf12000x.moitemp; update sf12000x.moi zpops90(in=inups); by sumlev geocode; if not inups and sumlev in ('871','881') and substr(zcta5,4,2) ne 'HH' then do; put sumlev geocode totpop ; _noups+1; if _noups gt 200 then abort abend; end; drop _noups; run; *--regenerate the index after updating-------; proc datasets library=sf1x; modify moitemp; index create sumlev; quit; proc format; value pop .='NA' other='Yes'; run; *--create views for stcnty, tracts, proc sql; create view sf12000x.mostcnty as select * from moi where SumLev in ('040','050'); quit; proc freq data=sf12000x.moi; table sumlev * totpop90/missing; format sumlev $3. totpop90 pop.; title2 'Freq Report Showing Summary Levels and Whether We Have a 1990 Pop Count for It'; run; proc contents data=sf12000x.moi; title2 'Contents'; run;