x cd /pub/data/saipe/Tools; %let pgm=cnvt_sahie; filename pgm "&pgm..sas"; *========================================saHie=================This is SAHIE data, NOT SAIPE!!!!=====; *---Convert state and county Small Area Health Insurance Estimates data from **************** Running with 2005 data Oct. 2008 Running with 2006 data Aug. 2009 Running with 2007 data Jul. 2010 rerunning with 2006 data and adding the TotFlag variable Oct 2009. Running with 2008 & 2009 data, Oct. 2011. Running with 2010 data, Aug, 2012. Running with 2011 data, Sep, 2013. Running with 2012 data, Mar, 2014. Running with 2013 & 2014 data, May, 2016. (Data my be different. Pop variable not present. year and version cols added.etc.) Running with 2015 data, April 2017. ----*; /*<=========================Comment out===================================== *--downloaded from http://www.census.gov/did/www/sahie/data/20082015/index.html 4/17 --; %let year=2013; *<==============================running 05-16-16=======; *--Ran the 2013 convert and now doing 2014 (same day)---; %let year=2014; *<==============================running 05-16-16=======; ===========================End commented out================================ */ %let year=2015; %let yr=%substr(&year,3,2); *--documentation misleading. We set numlev and pctfmt back to what they have always been with an extra column on each to account for blank columns on input. ---; %let numlen=9; *---input numeric fields were length 9 prior to 2010 data----------------; %let pctfmt=%str(5.1); *---pctage fields were in 5.1 format prior to 2010 data------------------; *----Starting with 2013 we (plan to at least) save the lisiintg/print file to cnvt_sahie&year..lst ---; libname saipe '/pub/data/saipe'; libname sahie (saipe); *filename txtin "/pub/data/saipe/sahie&yr.all.txt"; *--worked for year <= 2012--; filename txtin "/pub/data/saipe/sahie_&year..txt"; options mprint; title "cnvt_sahie: Convert health insurance estimates for &year from Census Bureau SAHIE program"; data saipe.sahie&yr(label="SAHIE Health Insurance Estimates for US states & counties, &year" index=(state)); infile txtin lrecl=255 termstr=crlf ; length TotFlag $1 asri $4 Year $4 SumLev $3 State $2 Stab $2 Fipco County $5 Areaname $45; length Agecat Racecat sexcat iprcat $1 nic nic_moe nui nui_moe nipr nipr_moe pctic pctic_moe pctui pctui_moe pctliic pctliic_moe pctelig pctelig_moe 5; %macro ifcode; %global lastmetatext; %if &year ge 2013 %then %let lastmetatext=%str(year|version); %else %let lastmetatext=%str(Datalines Follow); %if &year ge 2006 %then %do; length nipr pctic pctui pctliic 5 nipr_moe pctic_moe pctui_moe pctliic_moe 4; %end; %mend; %ifcode ; %put lastmetatext=&lastmetatext ***; ***column headers from the sahie_2013.txt file as downloaded: year|version|statefips|countyfips|geocat|agecat|racecat|sexcat|iprcat|NIPR|nipr_moe|NUI|nui_moe|NIC|nic_moe|PCTUI|pctui_moe|PCTIC|pctic_moe|PCTELIG|pctelig_moe|PCTLIIC|pctliic_moe|State Name|County Name| ;; retain year "&year"; if _n_=1 then do; *--flush metadata lines until we come to the line indicating we have reached the actual data--; do until (_infile_=:"&lastmetatext"); input; _nread+1; if _nread gt 100 then stop; end; end; %macro readit; %if &year ge 2013 %then %do; Length _Yearck $4 Version $8; input _Yearck $4. +1 Version $8. +1 %end; %else %do; input %end; %if &year ge 2013 %then %do; _st $2. +1 _co $3. +4 (Agecat Racecat sexcat iprcat)($1. +1) +1 (nipr nipr_moe nui nui_moe nic nic_moe)(8. +1) +1 (PctUI PctUI_moe PctIC PctIC_moe pctelig pctelig_moe PctLiic Pctliic_moe )(5.1 +1) ; *--We do not read the state and county name fields--; %end; %else %do; _st $2. +1 _co $3. +4 (Agecat Racecat sexcat iprcat)($1. +1) @18 (pop nic nic_moe nui nui_moe)(&numlen..) %if &year=2005 %then %do; @64 pctelig 4.1 +1 pctelig_moe 4.1 ; %end; %else %do; (nipr nipr_moe)(9.) (pctic pctic_moe pctui pctui_moe pctliic pctliic_moe pctelig pctelig_moe)(&pctfmt.) ; %end; %end; %if &year ge 2013 %then %do; if _n_=1 then do; if _yearck ne "&year" then do; put "Value read for year is " _Yearck " but parm says it should be &year . Aborting convert***"; abort abend; end; else put "**Begin processing data for " Year= Version= ; end; %end; *--TotFlag is "Y" or "N" depending on whether or not this is a total-across-all-categories summary. (It still only pertains to persons over 65, however). --; if agecat='0' and racecat='0' and sexcat='0' and iprcat='0' then TotFlag='Y'; else TotFlag='N'; *---Define the asri variable which is a string of letters indicating which of the 4 categories (age, sex, race and income) are relevant to this summary obs.----; if agecat ne '0' then asri='a'; if sexcat ne '0' then asri=trimn(asri)||'s'; if racecat ne '0' then asri=trimn(asri)||'r'; if iprcat ne '0' then asri=trimn(asri)||'i'; asri=left(asri); if length(_st)=1 then State='0'||_st; else State=_st; if _co=0 then County=state||'000'; else County=State||translate( right(_co),'0',' '); if _co=0 then do; Sumlev='040'; Areaname=put(state,$state.); end; else do; SumLev='050'; Areaname=put(county,$county.); end; Stab=put(state,$fipstab.); Fipco=County; Format County $county.; label TotFlag='Total Pop (<65) Flag' asri='Age Sex Race Income relevance code'; label agecat='Age Category' racecat='Race category' sexcat='Sex category' iprcat='Income category'; label pop='Number in age-race-sex group' nic='Number insured' nic_moe='Margin of error for number insured' nui='Number uninsured' nui_moe='Margin of error for number uninsured' pctelig='Pct uninsured in demographic group, all income levels' pctelig_moe='Margin of error for Pctelig'; %if &year ge 2006 %then %do; label nipr='Number in income-level group' nipr_moe='Margin of error for number in income-lvel grp' pctic='Pct insured in income-level demographic group' pctic_moe='MOE for pctic' pctui='Pct uninsured in income-level group' Pctui_moe='MOE for pctui' pctliic='Pct insured in demographic group for all income levels' pctliic_moe='MOE for pctliic'; %end; %mend readit; %readit ; format pct: 4.1; drop _: ; if _N_ le 5 then put / _all_; run; title3 "Contents of saipe.sahie&yr"; %contents(saipe.sahie&yr) title3 " "; proc format library=saipe.formats; value $Agecat 0 ="All(<65 yrs) " 1 ="18 to 64 yrs" 2 ="40 to 64 yrs" 3 ="50 to 64 yrs" 4 ="Under 19 yrs" 5="21 to 64 yrs"; *<--agecat 5 added with 2015 data--; Value $racecat 0 ="All races" 1 ="White alone, not Hispanic " 2 ="Black alone, not Hispanic" 3 ="Hispanic (any race)"; Value $Sexcat 0 ="Both sexes " 1 ="Male" 2 ="Female" ; Value $iprcat 0 ="All income levels" 1 ="At or below 200% of poverty " 2 ="At or below 250% of poverty"; run; *--Generate 4 companion format codes that repeat the code as part of the label--; %cnvt2wc($agecat,library=saipe,lenarg=1) %cnvt2wc($racecat,library=saipe,lenarg=1,fnameout=raccatwc) %cnvt2wc($sexcat,library=saipe,lenarg=1) %cnvt2wc($iprcat,library=saipe,lenarg=1) ; options fmtsearch=(sasctlgs saipe); data saipe.sahietotals&yr(label="Totals for all <65, subset of sahie&yr"); set saipe.sahie&yr; where totflag='Y'; drop totflag agecat sexcat racecat iprcat pctelig pctelig_moe pctliic pctliic_moe; run; proc print data= saipe.sahietotals&yr (where=(state="29")); by year state stab ; id sumlev county; title2 "Mo Subset of sahietotals&yr dataset" ; run; data saipe.mosahie&yr(label="MO subset of sahie&yr"); set saipe.sahie&yr; where state="29"; run; proc print data= saipe.mosahie&yr (where=(county in ('29000','29189'))); by year state stab sumlev county; title2 "Subset of mosahie&yr dataset" ; run; proc freq data=saipe.mosahie&yr; format agecat $agecatwc. racecat $raccatwc. sexcat $sexcatwc. iprcat $iprcatwc. ; tables TotFlag Sumlev agecat racecat sexcat iprcat; table asri /missing; title2 "Freq Report using Missouri subset: saipe.mosahie&yr"; run; proc sort data=saipe.mosahie&yr(keep=sumlev asri agecat sexcat racecat iprcat) nodupkeys out=mocodes; by sumlev asri agecat sexcat racecat iprcat; format agecat $agecatwc. racecat $raccatwc. sexcat $sexcatwc. iprcat $iprcatwc. ; run; proc print data=mocodes; by sumlev asri; id sumlev asri; var agecat sexcat racecat iprcat; title2 "Relevant Demographic Categories in mosahie&yr dataset"; run; /* =======================Begin comment================ proc tabulate data=saipe.sahie&yr; where sumlev='040'; title2 'Tabulate Report'; class sumlev state county agecat racecat sexcat iprcat; format state $fipstab. sumlev $sumlev.; format agecat $agecat. racecat $racecat. sexcat $sexcat. iprcat $iprcat. ; var nic nui pctelig nipr; table (all='US Totals' state), (agecat racecat sexcat iprcat), (nic nui nipr)*sum*f=comma13. ; run ; *<----Really not useful report because the categories are not crossed. Things are multi-counted. --; ======================End comment================== */