x cd /pub/data/acspums/Tools; %let pgm=povratios_c17002_pumas; filename pgm "&pgm..sas"; /* We want to extract data re the poverty ratios for all PUMAs in the US. for multiple years. Would like to do 5 years but we do not (as of 2017) have 5 years with the same (current) PUMAs. They used the old 2k PUMAs thru 2011. So we will only do 2012-2014 this run (only 3 years with 2013 as center). When we go to the next cycle we will be able to use 5 years of data (2012-1016). We plan to use these data to enhance our ability to define a Mean Poverty Ratio variable at the tract and BG level. (The 5yr data have a much cruder C17002 table for pov ratios, while the 1yr data is considerably more detailed. What we want to do hear is assign a mean P.R. value for each of the 7 intervals of table c17002. The PUMAs can be associated with census tracts so we get a custom set of interval estimates depending on the PUMA. Output datasets are named as follows: apr [average poverty ratios] _c17002 [indicates link with base table c17002 with poverty ratio intervals] _puma [indicating geographic level of the data] __ [indicates the interval of acs vintage years used. So 12_14 means we used 3 yrs of data 2012 to 2014. jgb, OSEDA, June 2017. */ libname acspums '/pub/data/acspums'; libname user '/SAS_temp/userb'; %macro povrates(year1,year2,sorts=1); *--specify sorts=0 if sort steps already ran----*; %let yr1=%substr(&year1,3,2); %let yr2=%substr(&year2,3,2); %if &sorts %then %do yr=&yr1 %to &yr2; proc sort data=acspums.usprecs&yr (keep=st puma povpip pwgtp where=(povpip)) out=d&yr.a; by st puma; run; proc sort data=acspums.usprecs&yr.b (keep=st puma povpip pwgtp where=(povpip)) out=d&yr.b; by st puma; run; %end; %let outset=acspums.apr_c17002_puma_&year1._&year2; data &outset (label="Avg Pov Ratios for C17002 intervals for &year1 to &year2 by PUMA" index=(state)); *---the a and b sets have different states on them. Mo-Wy are on the b sets---; retain Years "&year1.-&year2"; set %do yr=&yr1 %to &yr2; d&yr.a %end; %do yr=&yr1 %to &yr2; d&yr.b %end; ; * where st in ('01','29'); *<========while testing=====; by st puma; array _sum(7) _sum1-_sum7; array _povu(7) _povu1-_povu7; array _apr(7) apr0_49 apr50_99 apr100_124 apr125_149 apr150_184 apr185_199 apr200_up; if first.puma then do _i=1 to 7; _sum(_i)=0; _povu(_i)=0; end; if povpip <= 49 then _i=1; else if povpip <=99 then _i=2; else if povpip <= 124 then _i=3; else if povpip <= 149 then _i=4; else if povpip <= 184 then _i=5; else if povpip <= 199 then _i=6; else _i=7; _sum(_i) + povpip*pwgtp*.01; *--Stored on acs set as (for example) 125, which really means 1.25--; _povu(_i) + pwgtp; if last.puma then do; do _i=1 to 7; _apr(_i)=round( (_sum(_i)/_povu(_i) ),.001); end; format apr: 5.3; drop _: povpip pwgtp; rename st=State; output; end; run; proc datasets nolist library=acspums; %let outset2=%substr(&outset,9); %*--remove the leading "acspums." --; modify &outset2 ; index create stpuma=(state puma); quit; *---test the index--; data test; state='29'; puma='02800'; set &outset key=stpuma; put _all_; stop; run; ods listing close; ods html file="&pgm..html" style=ocean ; proc print data= &outset (obs=100); by Years state; format state $state.; id puma; ** var apr: _sum: _povu: ; title "&outset. : Average Pov Ratio Values for 7 Intervals in C17002 by PUMA"; title2 "First 100 Rows"; footnote h=.5 "from setup in /pub/data/acspums/Tools/&pgm..sas"; run; ods html close; %mend povrates; options mprint; %povrates(2012,2014,sorts=0);