x cd /pub/data/pl942010/Tools; %let pgm=pl94_usdatasets; filename pgm "&pgm..sas"; *---Now that we have converted all 50 + 1 states to sas data sets we want to create a series of national data sets with specific geographic levels. ---*; libname pl942010 '/pub/data/pl942010'; libname pl94 (pl942010); libname user '/SAS_temp/user'; title "&pgm.: Create National Datasets for Selected Geographic Levels"; %let pctvars=pctwhite1 pctblack1 pctindian1 pctasian1 pcthawnPI1 pctother1 pcthisppop pctwhitenh1 pctmultrace pctover18 pctunder18 popPSQMi pctvacant; %let wgtvars=Totpop totpop totpop totpop totpop totpop totpop totpop totpop totpop totpop landsqmi tothus; /* ========================begin comment==================================== %let set=usstates; data pl94.&set (label='State summaries, Entire U.S. + PR'); %macro doit(state,stab); pl94.&stab.sums(drop=County Tract cnty--gcuni lsadc--gnisanrc where=(sumlev='040')) %mend doit; *---we keep PR on most datasets, including this one---; set %dostates(n=52) open=defer; run; data first3; set pl94.usstates(obs=3); run; title2 "&set"; proc fsbrowse printall data=first3; run; ==========================end comment====================================== */ *===========================================================================================================================*; %let set=usregdiv; proc format; VALUE $DIVISIO "1"="New England" "2"="Middle Atlantic" "3"="East North Central" "4"="West North Central" "5"="South Atlantic" "6"="East South Central" "7"="West South Central" "8"="Mountain" "9"="Pacific" ; VALUE $region '1'='Northeast Region' '2'='Midwest Region' '3'='South Region' '4'='West Region'; run; proc sort data=pl94.usstates(where=(state ne '72')) out=states; by region division; run; %agg(setin=states,setout=regdiv, aggby=Region Division, agglvl=2, grand=1, aggvars=_numeric_,naggvars=57, means=&pctvars, mweights=&wgtvars, debug=0); proc sort; by region division; run; data pl94.&set(label='US Totals, Regions & Divisions'); length SumLev $3 Geoid $12 esriid $2 AreaName $40; set regdiv; if _lvl_=99 then do; SumLev='010'; Geoid='01000US'; esriid=' '; AreaName='United States'; end; if _lvl_= 1 then do; SumLev='030'; Geoid='03000US'||division; esriid=division; Areaname=put(division,$divisio.); end; if _lvl_= 2 then do; SumLev='020'; Geoid='02000US'||region; esriid=region; Areaname=put(region,$region.); end; drop _: Ngeo_id LogRecNo; drop IntPt: ; *<----cannot aggregate these----; run; proc sort; by geoid; run; proc fsbrowse printall data=pl94.&set; title2 "&set"; run; *===========================================================================================================================*; /* ========================begin comment==================================== %let set=uscounties; %macro doit(state,stab); pl94.&stab.sums(drop=Tract cousubfp--ConCit NECTA--sduni funcstat gcuni PartFlag--gnisanrc where=(sumlev='050')) %mend doit; data pl94.&set(label='All counties and county equivalents in U.S.' index=(state)); set %dostates(n=52) open=defer; format cbsa $cbsa.; run; proc print data=pl94.&set(obs=20); title2 "pl94.&set"; run; *===========================================================================================================================*; %let set=usplaces; %macro doit(state,stab); pl94.&stab.sums(drop=Tract cousubfp cousubcc bg block concit Necta: cnecta UrbanRur--sduni gcuni PartFlag--gnisanrc where=(sumlev in ('155','160'))) %mend doit; data pl94.usplaces(label='All places in U.S.: Complete and within-county' index=(state)); set %dostates(n=52) open=defer; run; proc sql; create view pl942010.usplaces10k(label='Complete U.S. Places with 10,000+ Pop') as select * from usplaces( drop=county cnty cntyCC cbsa: metdiv csa) where TotPop ge 10000 and SumLev='160'; create view pl942010.usplaces160(label='All U.S. Places - Level 160 only' ) as select * from usplaces(drop=county cnty cntyCC cbsa: metdiv csa) where SumLev='160'; quit; proc print data=pl94.&set(obs=20); title2 "pl94.&set"; run; proc print data=pl94.&set.10k(obs=20); title2 "pl94.&set.10k (View)"; run; proc print data=pl94.&set.160(obs=20); title2 "pl94.&set.160 (View)"; run; *===========================================================================================================================*; %let set=uscousubs; %macro doit(state,stab); pl94.&stab.sums(drop=Tract placefp--concit nectapci--sduni PartFlag--gnisanrc where=(sumlev ='060')) %mend doit; data pl94.&set(label='All county subdivisions (towns, townships, etc) in U.S.' index=(state)); set %dostates(n=52) open=defer; format county $county.; run; proc sql; create table pl94.netowns(label='New England towns and other county subdivisions') as select * from pl94.&set where Division='1' ; quit; proc print data=pl94.&set(obs=20); title2 "pl94.&set"; run; proc print data=pl94.netowns(obs=20); title2 "pl94.netowns"; run; proc freq data=pl94.&set(keep=state lsadc); by state; format lsadc $lsadc. state $fipstab.; table lsadc; title2 "&set : lsadc codes by state"; ==========================end comment====================================== */ *===========================================================================================================================*; %let set=uscbsas; proc sort data=pl94.uscounties out=counties; by cbsa state; run; %agg(setin=counties,setout=aggout, aggby=cbsa state, agglvl=2, grand=0, aggvars=_numeric_,idvars=csa, means=&pctvars, mweights=&wgtvars, debug=0); proc sort; by cbsa state; run; data pl94.&set(label='US CBSAs: Metropolitan/Micropolitan Stat Areas'); length SumLev $3 Geoid $12 esriid $7 AreaName $80 cbsatype $5; set aggout; if _lvl_= 2 then do; SumLev='310'; Geoid='31000US'||cbsa; esriid=cbsa; if cbsa='99999' then delete; else Areaname=put(cbsa,$cbsa.); if index(areaname,'Micropolitan') then cbsatype='micro'; else cbsatype='metro'; end; if _lvl_= 1 then do; SumLev='311'; Geoid='31100US'||cbsa||state; esriid=cbsa||state; if cbsa='99999' then areaname='Non-CBSA remainder of '||put(state,$state.); else Areaname=trim(put(cbsa,$cbsa.))||' / ' || put(state,$fipstab.); if cbsa ne '99999' then if index(areaname,'Micropolitan') then cbsatype='micro'; else cbsatype='metro'; end; format cbsa $5.; *--it was $cbsa. on the uscounties data set--; drop _: Ngeo_id LogRecNo; drop IntPt: ; *<----cannot aggregate these----; run; proc sort; by cbsa state ; run;