x cd /pub/data/popests/easidata; %let pgm=splitbgs07; filename pgm "&pgm..sas"; ****See the setup in P:\estpro07\geolytics07.sas which runs from PC side and creates the input dataset used here***; *---Calculate total pops for all (level 150) bgs in country and merge with the latest easi analytics data to create a US level 090 dataset with pro-rated ests and projections. This is also the setup where we define the compiled macro easipwd. <===================== ---*; %let eyr=07; %let pyr=12; *--estimate year and projection year for which we have data--; %let years=07_12; *--same thing--; title "&pgm: Retabulate easidata Estimates and Projections to Other Geographic Levels"; libname easidata '/pub/data/popests/easidata'; libname xxsl090 '/pub/data/census_2000/sf32000x/xxsl090'; libname temp '/SAS_temp/user'; libname user '/SAS_temp/user'; %libname(sf32000x); options mstored sasmstore=library; options nosource; /* =======================Begin comment================ *---Following step is run interactively and only once----------------------------------------------*; %macro easipwd / store source des='Generate EASI data pwd'; Not2EZ %mend easipwd; data _null_; retain pwd "%easipwd"; put _all_; run; ======================End comment================== */ options source; %global doover; %macro doit(state,stab); data _null_; if exist("easidata.&stab.090bgs&years") then doover='1'; else doover='0'; call symput ("doover",doover); stop; run; %if &doover %then %do; proc datasets nolist library=easidata; delete &stab.090bgs&years / alter=%easipwd; quit; %end; proc sort data=xxsl090.&stab.sl090(keep=state county cousubfp placefp tract urbanrur bg totpop) out=keys; by county tract bg cousubfp placefp urbanrur; run; %corrwt(setin=keys,setout=temp.&stab.clist, g1=county tract bg, g2=cousubfp placefp urbanrur,idvars=state, wtvar=totpop,keepwt=1) %let wherepass=1; %if &state=08 %then %do; %*--put new Broomfield county codes back to 2000 values to match with 2k census data--; data cobgs&years; set easidata.usbgs&years(where=(state="&state") password=%easipwd keep=state county tract bg popest&eyr popproj&pyr); if county='08014' then do; length _tract4 $4; _tract4=tract; select(_tract4); when('0085') county='08001'; when('0131') county='08013'; when('0098') county='08059'; when('0020') county='08123'; end; end; drop _tract4; run; proc sort; by state county tract bg; run; %let easiset=cobgs&years; %let wherepass=0; %end; %else %if &state=51 %then %do; %*---Put Clifton Forge back to independent city county code---; data vabgs&years; set easidata.usbgs&years(where=(state="&state") password=%easipwd keep=state county tract bg EsriID popest&eyr popproj&pyr ); *--Tract 701 = the city of Clifton Forge, which was an independent city in 2000 with 560 cnty code. It was put back into Alleghany county after the census so that tract 701 geos now appear under cnty code (51)005. --; if Esriid=:'51005070100' then county='51560'; run; proc sort; by state county tract bg; run; %let easiset=vabgs&years; %let wherepass=0; %end; %else %let easiset=easidata.usbgs&years; data &stab.bgs; merge &easiset ( %if &wherepass %then %do; where=(state="&state") password=%easipwd %end; keep=state county tract bg popest&eyr popproj&pyr in=ineasi) temp.&stab.clist(in=inclist); by state county tract bg; if not (ineasi and inclist) then do; put '****bg not in both datasets**** ' ineasi= inclist= county= tract= bg=; _nerr+1; if _nerr ge 5 then abort abend; end; if first.bg then do; _saveest=popest&eyr; _saveproj=popproj&pyr; _est=0; _proj=0; end; retain _save: ; if afact lt 1 then do; popest&eyr=round(_saveest*afact,.1); popproj&pyr=round(_saveproj*afact,.1); end; _est + popest&eyr; _proj+ popproj&pyr; if last.bg then do; if _est=0 then popest&eyr=_saveest; if _proj=0 then popproj&pyr=_saveproj; end; format popest&eyr popproj&pyr 8.1; ***if county='01001' and tract='0206.00' and bg='1' then put / _all_; drop _: ; run; proc sort data=&stab.bgs out=easidata.&stab.090bgs&years(label='Estimates and Projections allocated to level 090' password=%easipwd); by county cousubfp placefp tract Urbanrur bg; run; proc datasets library=easidata nolist; modify &stab.090bgs&years (alter=%easipwd); index create geokey=(county cousubfp placefp tract Urbanrur bg); quit; %mend doit; options NOmprint; %***dostates(names=1,msgs1=); %dostates(51 53 54 55 56,names=1,msgs=1) ; *----Temporary test step to make sure we can access the data using keyed access------------------*; data test; set xxsl090.alsl090(keep=_char_ totpop) end=last; set easidata.al090bgs&years (password=%easipwd) key=geokey; if _iorc_ then do; put / _all_; stop; end; statetot + popest&eyr; if last then put statetot=; run cancel; *-----------And now we create the usmcds dataset to be used by the caps application---------------; %macro fipstab(state,stab); easidata.&stab.090bgs&years (password=%easipwd) %mend fipstab; data usmcds; set %dostates(mac=fipstab) ; keep state county cousubfp pop: ; run; proc sort; by county cousubfp; run; proc summary nway data=usmcds; class county cousubfp; id state; var popest&eyr popproj&pyr; output out=easidata.usmcds07(password=%easipwd drop=_type_ _freq_) sum=; run; proc datasets library=easidata nolist; modify usmcds07 (alter=%easipwd); index create geokey=(county cousubfp); quit; *---test the new dataset to make sure we can read it, keyed---; data test2; set sf32000x.usmcds07 (keep=_char_ totpop); where state='01'; set easidata.usmcds (password=%easipwd) key=geokey; if _n_ le 5 then put _all_; if _iorc_ then do; put / '***error*** ' _all_; stop; end; run; data aggin2/view=aggin2; set easidata.usbgs&years(password=%easipwd); run; %agg(aggin=aggin2, aggout=aggout, aggby=state county,aggvars=popest&eyr popproj&pyr,agglvl=2, grand=1) run; proc print data=aggout (keep=_lvl_ state pop:); where _lvl_=2; id State; format state $state.; var pop:; format pop: comma13.; sum pop: ; title2 "State Totals Aggregated from Original easidata.usbgs&years"; run; data aggin/view=aggin; set easidata.usmcds(password=%easipwd); run; %agg(aggin=aggin, aggout=easidata.usstcnty07, aggby=state county,aggvars=popest&eyr popproj&pyr,agglvl=2, grand=1) run; proc print data=easidata.usstcnty07 (keep=_lvl_ state pop:); where _lvl_=2; id State; format state $state.; var pop:; format pop: comma13.; sum pop: ; title2 'State Totals Aggregated from easidata.usmcds'; run; proc print data=easidata.usstcnty07 (where=(state='29')); by state notsorted; format state $state.; id _lvl_ county; format county $county.; title2 'easidata.usstcnty07 - MO Subset'; run; %include sascode(notify);