x cd /pub/data/sf32000x/Tools; %let pgm=avg_cd2000_size_by_state; filename pgm "&pgm..sas"; *---Calculate and print a report showing the average persons per Congressional District in 2000. Are all persons represented equally in the House of Reps?----; libname sf32000x '/pub/data/census_2000/sf32000x' access=readonly; *---this file (csvin) was generated using Geocorr2k per the saved query file saved in Tools/geoocrr2k_cdpops108.htm --; filename csvin '/pub/data/sf32000x/geocorr2k_cdpops108.csv'; options nodate; ods pdf file="&pgm..pdf"; data report106; set sf32000x.usother(keep=sumlev state totpop100); where sumlev='500' and state not in ('11','72'); by state; if first.state then do; Ndistricts=0; StatePop=0; end; Ndistricts+1; statepop+totpop100; if last.state then do; _USndistricts+Ndistricts; _UStotpop+statepop; AvgPopPerCD=statepop/Ndistricts; output; if state='56' then do; state='00'; ndistricts=_usndistricts; statepop+_ustotpop; AvgPopPerCD=statepop/Ndistricts; output; end; end; attrib avgpoppercd format=comma9. label='Avg Persons Per CD'; label Ndistricts='# CDs' statepop='State Total Pop'; format state $state.; drop _: ; run; proc print data=report106 label; id state; var Ndistricts Statepop Avgpoppercd; title "&pgm.: Average Population of 106th Congessional Districts by State"; title2 "Using 2000 Census Data and CD Defns"; run; proc sort data=report106; by descending avgpoppercd ; proc print data=report106 label; ***id state; where state ne '00'; var state Ndistricts Statepop Avgpoppercd; title "&pgm.: Average Population of 106th Congessional Districts by State"; title2 "Using 2000 Census Data and CD Defns"; title3 'Sorted by Descending Avg Persons Per CD'; run; *--------------------Repeat similar processing using population data and 108th CD geography taken from geocorr2k------------; data pops108; infile csvin firstobs=3 dsd ; length State $2 cd108 $2 stab $2 totpop100 5; input state -- totpop100; if length(state)=1 then state='0'||state; if length(cd108)=1 then cd108='0'||cd108; if state ne '11'; run; data report108; set pops108; by state; if first.state then do; Ndistricts=0; StatePop=0; end; Ndistricts+1; statepop+totpop100; if last.state then do; _USndistricts+Ndistricts; _UStotpop+statepop; AvgPopPerCD=statepop/Ndistricts; output; if state='56' then do; state='00'; ndistricts=_usndistricts; statepop+_ustotpop; AvgPopPerCD=statepop/Ndistricts; output; end; end; attrib avgpoppercd format=comma9. label='Avg Persons Per CD'; label Ndistricts='# CDs' statepop='State Total Pop'; format state $state.; drop _: ; run; proc print data=report108 label; id state; var Ndistricts Statepop Avgpoppercd; title "&pgm.: Average Population of 108th Congessional Districts (After 2k-based Reapportionment), by State"; title2 "Using 2000 Census Data Generated by Geocorr2k"; run; proc sort data=report108; by descending avgpoppercd ; proc print data=report108 label; ***id state; where state ne '00'; var state Ndistricts Statepop Avgpoppercd; title "&pgm.: Average Population of 108th Congessional Districts (After 2k-based Reapportionment), by State"; title2 "Using 2000 Census Data Generated by Geocorr2k"; title3 'Sorted by Descending Avg Persons Per CD'; run; ods pdf close;