x cd /pub/data/dpro2010/Tools; %let pgm=cnvt_dpro_files; filename pgm "&pgm..sas"; *--- Reads the 2010 Census Demographic Profile summary files as downloaded from https://www.census.gov/embargo/pio/ (starting 5-3-11) Coded by John Blodgett, OSEDA, U. of Missouri, Columbia, MO. Under contract with the Missouri Census Data Center. ----*; %let embargoed=0; *<--set to 1 prior to embargo being lifted---; libname dpro2010 '/pub/data/dpro2010'; *--This is the directory where the output data sets are saved--; libname dpro (dpro2010); *--alternate name---; %let maxobs=max; *--assign parm a value of max to do a complete run or some numeric value to limit processing to that many rows--; %let filesfx=%str(.dp); *---ids the kind of data file---; options compress=no; title "dpro2010/Tools/&pgm.: Convert 2010 Demographic Profile Summary Files"; x cd /pub/data/dpro2010; *<-----the steps to unzip the .zip files at the start and delete them at the end wont work without this-------; %macro doit(state, stab); %*--this is the macro that will be invoked once for each state converted using the dostates driver macro--; %let stabu=%upcase(&stab); %*--upper case: used to verify that the file we are reading is correct-; %let stfips=&state; %*--FIPS state code--; data _null_; call system("unzip &stab.2010.dp.zip"); run ; %if &sysrc gt 0 %then %do; %put ***Non-zero system return code while attempting to unzip files for state: &state &stab &statenm ; %goto dontdoit; %end; title "Convert 2010 PL94-171 Files for &statenm"; *---This code reflects the file-naming conventions found insided the downloaded .zip files from the FTP site---; filename in1 "/pub/data/dpro2010/&stab.000012010&filesfx"; filename ingeo "/pub/data/dpro2010/&stab.geo2010&filesfx"; *-------------Step 1: Read the comma-delimited dpro dp (Data Profile 2010) files ------------*; data dpsf; ******retain state "&state"; *--assign FIPS state code as constant--; length default=5; infile in1 lrecl=4096 obs=&maxobs missover dsd; *<---------------Read input file 1----------------; input _first15 $char15. LogRecNo 7. +1 dpsf1i1-dpsf1i57 dpsf2i1-dpsf2i3 dpsf3i1-dpsf3i3 dpsf4i1-dpsf4i3 dpsf5i1-dpsf5i3 dpsf6i1-dpsf6i3 dpsf7i1-dpsf7i3 dpsf8i1-dpsf8i24 dpsf9i1-dpsf9i6 dpsf10i1-dpsf10i7 dpsf11i1-dpsf11i17 dpsf12i1-dpsf12i20 dpsf13i1-dpsf13i15 dpsf14i1 dpsf15i1 dpsf16i1 dpsf17i1 dpsf18i1-dpsf18i9 dpsf19i1 dpsf20i1 dpsf21i1-dpsf21i3 dpsf22i1-dpsf22i2 dpsf23i1-dpsf23i2 ; format dpsf2i: dpsf19i1 dpsf20i1 5.1 dpsf16i1 dpsf17i1 dpsf23i: 6.2; /* DPSF1. SEX AND AGE [57] */ /* Universe: Total population */ Label dpsf1i1 ="Total:" dpsf1i2 ="Under 5 years" dpsf1i3 ="5 to 9 years" dpsf1i4 ="10 to 14 years" dpsf1i5 ="15 to 19 years" dpsf1i6 ="20 to 24 years" dpsf1i7 ="25 to 29 years" dpsf1i8 ="30 to 34 years" dpsf1i9 ="35 to 39 years" dpsf1i10 ="40 to 44 years" dpsf1i11 ="45 to 49 years" dpsf1i12 ="50 to 54 years" dpsf1i13 ="55 to 59 years" dpsf1i14 ="60 to 64 years" dpsf1i15 ="65 to 69 years" dpsf1i16 ="70 to 74 years" dpsf1i17 ="75 to 79 years" dpsf1i18 ="80 to 84 years" dpsf1i19 ="85 years and over" dpsf1i20 ="Male:" dpsf1i21 =" Under 5 years" dpsf1i22 =" 5 to 9 years" dpsf1i23 =" 10 to 14 years" dpsf1i24 =" 15 to 19 years" dpsf1i25 =" 20 to 24 years" dpsf1i26 =" 25 to 29 years" dpsf1i27 =" 30 to 34 years" dpsf1i28 =" 35 to 39 years" dpsf1i29 =" 40 to 44 years" dpsf1i30 =" 45 to 49 years" dpsf1i31 =" 50 to 54 years" dpsf1i32 =" 55 to 59 years" dpsf1i33 =" 60 to 64 years" dpsf1i34 =" 65 to 69 years" dpsf1i35 =" 70 to 74 years" dpsf1i36 =" 75 to 79 years" dpsf1i37 =" 80 to 84 years" dpsf1i38 =" 85 years and over" dpsf1i39 ="Female:" dpsf1i40 =" Under 5 years" dpsf1i41 =" 5 to 9 years" dpsf1i42 =" 10 to 14 years" dpsf1i43 =" 15 to 19 years" dpsf1i44 =" 20 to 24 years" dpsf1i45 =" 25 to 29 years" dpsf1i46 =" 30 to 34 years" dpsf1i47 =" 35 to 39 years" dpsf1i48 =" 40 to 44 years" dpsf1i49 =" 45 to 49 years" dpsf1i50 =" 50 to 54 years" dpsf1i51 =" 55 to 59 years" dpsf1i52 =" 60 to 64 years" dpsf1i53 =" 65 to 69 years" dpsf1i54 =" 70 to 74 years" dpsf1i55 =" 75 to 79 years" dpsf1i56 =" 80 to 84 years" dpsf1i57 =" 85 years and over" ; /* DPSF2. MEDIAN AGE BY SEX [3] */ /* Universe: Total population */ Label /* Median age- */ dpsf2i1 ="Both sexes" dpsf2i2 ="Male" dpsf2i3 ="Female" ; /* DPSF3. SEX FOR THE POPULATION 16 YEARS AND OVER [3] */ /* Universe: Population 16 years and over */ Label dpsf3i1 ="Total:" dpsf3i2 ="Male" dpsf3i3 ="Female" ; /* DPSF4. SEX FOR THE POPULATION 18 YEARS AND OVER [3] */ /* Universe: Population 18 years and over */ Label dpsf4i1 ="Total:" dpsf4i2 ="Male" dpsf4i3 ="Female" ; /* DPSF5. SEX FOR THE POPULATION 21 YEARS AND OVER [3] */ /* Universe: Population 21 years and over */ Label dpsf5i1 ="Total:" dpsf5i2 ="Male" dpsf5i3 ="Female" ; /* DPSF6. SEX FOR THE POPULATION 62 YEARS AND OVER [3] */ /* Universe: Population 62 years and over */ Label dpsf6i1 ="Total:" dpsf6i2 ="Male" dpsf6i3 ="Female" ; /* DPSF7. SEX FOR THE POPULATION 65 YEARS AND OVER [3] */ /* Universe: Population 65 years and over */ Label dpsf7i1 ="Total:" dpsf7i2 ="Male" dpsf7i3 ="Female" ; /* DPSF8. RACE [24] */ /* Universe: Total population */ Label dpsf8i1 ="Total:" dpsf8i2 ="Population of one race:" dpsf8i3 =" White" dpsf8i4 =" Black or African American" dpsf8i5 =" American Indian and Alaska Native" dpsf8i6 ="Asian:" dpsf8i7 =" Asian Indian" dpsf8i8 =" Chinese" dpsf8i9 =" Filipino" dpsf8i10 =" Japanese" dpsf8i11 =" Korean" dpsf8i12 =" Vietnamese" dpsf8i13 =" Other Asian" dpsf8i14 ="Native Hawaiian and Other Pacific Islander:" dpsf8i15 =" Native Hawaiian" dpsf8i16 =" Guamanian or Chamorro" dpsf8i17 =" Samoan" dpsf8i18 =" Other Pacific Islander" dpsf8i19 =" Some Other Race" dpsf8i20 =" Population of Two or More Races" dpsf8i21 =" White; American Indian and Alaska Native" dpsf8i22 =" White; Asian" dpsf8i23 =" White; Black or African American" dpsf8i24 =" White; Some Other Race" ; /* DPSF9. RACE (TOTAL RACES TALLIED) [6] */ /* Universe: Total races tallied */ Label dpsf9i1 ="White alone or in combination" dpsf9i2 ="Black or African American" dpsf9i3 ="American Indian and Alaska Native" dpsf9i4 ="Asian" dpsf9i5 ="Native Hawaiian and Other Pacific Islander" dpsf9i6 ="Some Other Race" ; /* DPSF10. HISPANIC OR LATINO BY SPECIFIC ORIGIN [7] */ /* Universe: Total population */ Label dpsf10i1 ="Total:" dpsf10i2 ="Hispanic or Latino (of any race):" dpsf10i3 =" Mexican" dpsf10i4 =" Puerto Rican" dpsf10i5 =" Cuban" dpsf10i6 =" Other Hispanic or Latino" dpsf10i7 =" Not Hispanic or Latino" ; /* DPSF11. HISPANIC OR LATINO AND RACE [17] */ /* Universe: Total population */ Label dpsf11i1 ="Total:" dpsf11i2 ="Hispanic or Latino:" dpsf11i3 =" White alone" dpsf11i4 =" Black or African American alone" dpsf11i5 =" American Indian and Alaska Native alone" dpsf11i6 =" Asian alone" dpsf11i7 =" Native Hawaiian and Other Pacific Islander alone" dpsf11i8 =" Some Other Race alone" dpsf11i9 =" Two or More Races" dpsf11i10 ="Not Hispanic or Latino:" dpsf11i11 =" White alone" dpsf11i12 =" Black or African American alone" dpsf11i13 =" American Indian and Alaska Native alone" dpsf11i14 =" Asian alone" dpsf11i15 =" Native Hawaiian and Other Pacific Islander alone" dpsf11i16 =" Some Other Race alone" dpsf11i17 =" Two or More Races" ; /* DPSF12. RELATIONSHIP [20] */ /* Universe: Total population */ Label dpsf12i1 ="Total:" dpsf12i2 ="In households:" dpsf12i3 =" Householder" dpsf12i4 =" Spouse" dpsf12i5 =" Child" dpsf12i6 =" Own child under 18 years" dpsf12i7 =" Other relatives" dpsf12i8 =" Under 18 years" dpsf12i9 =" 65 years and over" dpsf12i10 =" Nonrelatives" dpsf12i11 =" Under 18 years" dpsf12i12 =" 65 years and over" dpsf12i13 =" Unmarried partner" dpsf12i14 ="In group quarters:" dpsf12i15 ="Institutionalized population:" dpsf12i16 =" Male" dpsf12i17 =" Female" dpsf12i18 ="Noninstitutionalized population:" dpsf12i19 =" Male" dpsf12i20 =" Female" ; /* DPSF13. HOUSEHOLDS BY TYPE [15] */ /* Universe: Households */ Label dpsf13i1 ="Total:" dpsf13i2 ="Family households (families):" dpsf13i3 =" With own children under 18 years" dpsf13i4 =" Husband-wife family" dpsf13i5 =" With own children under 18 years" dpsf13i6 =" Male householder, no wife present" dpsf13i7 =" With own children under 18 years" dpsf13i8 =" Female householder, no husband present" dpsf13i9 =" With own children under 18 years" dpsf13i10 ="Nonfamily households:" dpsf13i11 =" Householder living alone:" dpsf13i12 =" Male:" dpsf13i13 =" 65 years and over" dpsf13i14 =" Female:" dpsf13i15 =" 65 years and over" ; /* DPSF14. HOUSEHOLDS WITH INDIVIDUALS UNDER 18 YEARS [1] */ /* Universe: Households with individuals under 18 years */ Label dpsf14i1 ="Total" ; /* DPSF15. HOUSEHOLDS WITH INDIVIDUALS 65 YEARS AND OVER [1] */ /* Universe: Households with individuals 65 years and over */ Label dpsf15i1 ="Total" ; /* DPSF16. AVERAGE HOUSEHOLD SIZE [1] */ /* Universe: Households */ Label dpsf16i1 ="Average household size" ; /* DPSF17. AVERAGE FAMILY SIZE [1] */ /* Universe: Families */ Label dpsf17i1 ="Average family size" ; /* DPSF18. HOUSING OCCUPANCY [9] */ /* Universe: Total housing units */ Label dpsf18i1 ="Total:" dpsf18i2 ="Occupied housing units" dpsf18i3 ="Vacant housing units:" dpsf18i4 =" For rent" dpsf18i5 =" Rented, not occupied" dpsf18i6 =" For sale only" dpsf18i7 =" Sold, not occupied" dpsf18i8 =" For seasonal, recreational, or occasional use" dpsf18i9 =" All other vacants" ; /* DPSF19. HOMEOWNER VACANCY RATE [1] */ /* Universe: Owner-occupied, vacant for sale, and vacant sold but not occupied housing units */ Label dpsf19i1 ="Homeowner vacancy rate (percent)" ; /* DPSF20. RENTAL VACANCY RATE [1] */ /* Universe: Renter-occupied, vacant for rent, and vacant rented but not occupied housing units */ Label dpsf20i1 ="Rental vacancy rate (percent)" ; /* DPSF21. HOUSING TENURE [3] */ /* Universe: Occupied housing units */ Label dpsf21i1 ="Total:" dpsf21i2 ="Owner-occupied housing units" dpsf21i3 ="Renter-occupied housing units" ; /* DPSF22. POPULATION IN OCCUPIED HOUSING UNITS BY TENURE [2] */ /* Universe: Population in occupied housing units */ Label dpsf22i1 ="Owner-occupied housing units" dpsf22i2 ="Renter-occupied housing units" ; /* DPSF23. AVERAGE HOUSEHOLD SIZE OF OCCUPIED HOUSING UNITS BY TENURE [2] */ /* Universe: Occupied housing units */ Label /* Average household size- */ dpsf23i1 ="Owner-occupied" dpsf23i2 ="Renter-occupied" ; %local stus; %if %superq(stab)=us %then %let stus=US; %else %let stus=ST; if _first15 ne "DP&stus.,&stabu.,000,01," then do; _bad15+1; put _first15=; if _bad15 ge 25 then abort 100; *--Just a precaution --; end; drop _: ; run; filename in1 clear; *------------Step 2: Read the geography headers file ------*; data &stab.geos(compress=no); length LogRecNo 5 GeoId $48 SumLev $3 AreaName $90; *--establish variable order -- these go first--; retain State "&state" Stab "&stab"; length County $5; *** Tract $7; *--and then these... -; length esriid $20; *<---key to match esri shape files as stored in msdis online collection--; infile ingeo lrecl=512 obs=&maxobs; input @9 SumLev $3. Geocomp $2. @19 LogRecNo 7. @26 Region $1. Division $1. State $2. Cnty $3. CntyCC $2. CntySC $2. @37 CouSubFP $5. CouSubCC $2. CouSubSC $2. PlaceFP $5. PlaceCC $2. /* PlaceDC $1. */ PlaceSC $2. @69 ConCit $5. +2 AIANHH $4. AIANHHFP $5. AIANHHCC $2 @106 ANRC $5. @113 CBSA $5. CBSASC $2. MetDiv $5. CSA $3. NECTA $5. NECTASC $2. NECTADiv $5. CNECTA $3. CBSAPCI $1. NECTAPCI $1. @153 UrbanRur $1. cd111 $2. (sldu sldl)($char3.) @199 (AreaLand AreaWatr)(14.0) AreaName $90. FuncStat $1. gcuni $1. @319 Pop100 9. HU100 9. IntPtLat 11.6 IntPtLon 12.6 LSADC $2. @362 PartFlag $1. @374 (GNISState GNISCounty GNISCousub GNISPlace )($8.); %if &state=00 %then %do; if sumlev in ('040','500') then do; stab=put(state,$fipstab.); if sumlev='500' then areaname=upcase(stab)||" - "||areaname; end; else do; state=' '; stab=' '; end; %end; if cnty ne ' ' then County=state||cnty; select(SumLev); *---Assign the standardized Geographic Code to uniquely ID the geographic area--; when('610') Geoid=cat(sumlev,geocomp,"US",state,sldu); when('620') Geoid=cat(sumlev,geocomp,"US",state,sldl); when('500') Geoid=cat(sumlev,geocomp,"US",state,cd111); when('170') Geoid=cat(sumlev,geocomp,"US",state,concit); when('160') Geoid=cat(sumlev,geocomp,"US",state,placefp); when('230') Geoid=cat(sumlev,geocomp,"US",anrc); when('250') Geoid=cat(sumlev,geocomp,"US",aianhhfp); when('310') Geoid=cat(sumlev,geocomp,"US",cbsa); when('320') Geoid=cat(sumlev,geocomp,"US",state,cbsa); when('314') Geoid=cat(sumlev,geocomp,"US",cbsa,metdiv); when('323') Geoid=cat(sumlev,geocomp,"US",state,cbsa,metdiv); when('330') Geoid=cat(sumlev,geocomp,"US",csa); when('340') Geoid=cat(sumlev,geocomp,"US",state,csa); when('230') Geoid=cat(sumlev,geocomp,"US",aianhhfp); when('280') Geoid=cat(sumlev,geocomp,"US",state,aianhhfp); when('060') Geoid=cat(sumlev,geocomp,"US",county,cousubfp); when('050') Geoid=cat(sumlev,geocomp,"US",county); when('040') Geoid=cat(sumlev,geocomp,"US",state); when('030') Geoid=cat(sumlev,geocomp,"US",division); when('020') Geoid=cat(sumlev,geocomp,"US",region); when('01') Geoid=cat(sumlev,geocomp,"US"); otherwise do; if sumlev ne lag(sumlev) then do; put '****Unexpected SumLev code encountered: No value assigned to Geoid: ' SumLev= areaname=; end; end; end; *--select group--; esriid=substr(geoid,8); *--Create land and total area values in square miles. --; LandSQMI=AreaLand/2589988; AreaSQMI=LandSQMI + (AreaWatr/2589988); format LandSQMI AreaSQMI 9.2; label SumLev='Geographic Summary Level'; label LandSQMI='Land Area Sq Mls' AreaSQMI='Total Area Sq Mls' AreaLand='Land Area Sq Meters' AreaWatr='Water Area Sq Meters'; drop cntysc placesc cbsasc cousubsc ; *<---Not filled in for dpro files---; drop necta: ; drop _: ; run; /* ========================begin comment==================================== *---These steps for debugging purposes only---*; data toprint; set; by sumlev notsorted; if first.sumlev then _n=0; _n+1; if _n le 15; if sumlev='060' then if cnty='001'; run; proc sort; by sumlev; options ls=160 ps=90; proc print data=toprint; by state stab sumlev; format sumlev $sumlevwc.; id logrecno; title2 "&stab.geos"; run; ==========================end comment====================================== */ filename ingeo clear; *-------------------Step 3: Create the dpro.&stab.pros data set------------*; data dpro2010.&stab.pros(label="Demographic Profiles for &statenm") ; merge &stab.geos(in=ing) dpsf(in=ind); by logrecno; if ind; if not ing then do; put '**Geo Header Data missing : ' _n_= LogRecNo= areaname=; _nomatch+1; if _nomatch ge 100 then abort abend; drop _nomatch; ***areaname ; delete; end; run; *---delete the unzipped input files---; data _null_; call system("rm &stab.*&filesfx"); call system("rm &stab.2010&filesfx..prd.packinglist.txt"); %if &embargoed %then %do; call system("chmod o-r &stab.pros.sas7bdat"); *<----------------ONLY while embargoes====================; %end; run; %if &sysrc gt 0 %then %do; %put ***Non-zero system return code while attempting to delete upl files for &state &stab ***; %end; %dontdoit: %mend doit; options mprint; /* ========================begin comment==================================== *--Census Bureau to Release 2010 Census Demographic Profiles for the District of Columbia, Florida, Kentucky, Maine, Massachusetts, Michigan, Mississippi, New Mexico, North Dakota, Rhode Island, South Carolina, Tennessee and West Virginia --; %dostates(11 12 21 23 25 26 28 35 38 44 45 47 54,names=1); *--Media Advisory ? Census Bureau to Release 2010 Census Demographic Profiles for Alaska, Arizona, California, Connecticut, Georgia, Idaho, Minnesota, Montana, New Hampshire, New York, Ohio, Puerto Rico and Wisconsin -; %dostates(02 04 06 09 13 16 27 30 33 36 39 72 55,names=1); %dostates(01 08 10 15 20 29 31 32 37 42 49 53 56,names=1); %dostates(05 17 18 19 22 24 34 40 41 46 48 50 51 ,names=1); %let statenm=%str(United States); %doit(00,us) ==========================end comment====================================== */ %dostates(34,names=1); *--You can delete this line--;