x cd /pub/data/sf32000x/Tools; %let pgm=cnvtsf3x_xxslds; filename pgm "&pgm..sas"; /*---Access Census 2000 full sf3 datasets and create standard extract datasets and/or metadata (Variables) dataset. (This is just the same as cnvtsf3x_&xx.slds but with the state specified as a parm now). ---*/ %let xx=mi; %let state=26; %let statenm=Michigan; *<======2-11-2002==============; %let setin=&xx.slds; %let dvmode=data; *--required by dovar macro which is invoked dozens of times by the invoke_dovars module--; title "&pgm: Create sf32000x Extract Datasets from sf32000 Datasets - For &statenm"; libname sf3 "/pub/data/sf32000" access=readonly; libname sf3x "/pub/data/sf32000x"; *----the dovar macro is where the work is actually done. Below, the included invoke_dovars.sas serves as the "driver" which invokes this macro once per variable. ---; options NOmprint; *---------Here is the (1st) conversion data step-------------*; data sf3x.&&xx.slds (label="&statenm State Legislative District (complete) Summaries") sf3x.&&xx.sldcos(label="&statenm State Legislative District within county Summaries"); length default=5 Obs 5 esriid $16; retain State "&state"; merge sf3.&setin.ph sf3.&setin.phct(in=inct rename=(areaname=areanameck)); * by logrecno; *-----No key used -- we merge obs by obs, dangerous!!!!!!!!!!!!!!!!!!!!---; if areaname ne areanameck then do; _error_=1; put //'*******Error: Areaname check fails when merging ph and phct input sets**** ' _n_= Areaname= Areanameck= ; abort abend; end; drop areanameck; %include 'invoke_dovars.sas'/NOsource2; esriid=compress(geocode,'-.'); grcid=esriid; *---Edit the areaname field for cd108/county summaries. They were wrong for Michigan datasets--; if sumlev='510' and state ne '29' then do; _ix=index(areaname,'/'); if _ix then substr(areaname,_ix+1)=put(county,$county.); end; if sumlev in ('610','620') then do; _obs1+1; Obs=_obs1; output sf3x.&&xx.slds; end; else do; _obs2+1; Obs=_obs2; output sf3x.&&xx.sldcos; end; label esriid='Id field to link to ESRI map files' grcid='Id field to link to GRC/MsDIS map files (Mo only)'; keep Obs esriid geocode sldcode sldu02 sldl02 sumlev areaname state county partflag; keep TotPop -- grcid; label Obs='Observation #'; run; *----Create views for house and senate unsplit----; proc sql; create view sf3x.&&xx.senate as select sldu02 as Senate, * from &xx.slds where sumlev ='610'; create view sf3x.&&xx.house as select sldl02 as House, * from &xx.slds where sumlev ='620'; quit; run; proc means data=sf3x.&&xx.slds(keep=sumlev totpop) n sum maxdec=0; class sumlev; var totpop; title2 "Check Sums by Sumlev on sf3x.&xx.slds dataset"; run; *---------Here is the (2nd) conversion data step, for cd108-------------*; %let setin=&xx.cd108; data sf3x.&&xx.cd108 (label="&statenm 108th Congressional District Summaries"); length default=5 Obs 5 geocode esriid $5; retain State "&state"; merge sf3.&setin.ph sf3.&setin.phct(in=inct rename=(areaname=areanameck)); * by logrecno; by cd108; *-----No key used -- we merge obs by obs, dangerous!!!!!!!!!!!!!!!!!!!!---; if areaname ne areanameck then do; _error_=1; put //'*******Error: Areaname check fails when merging ph and phct input sets**** ' _n_= Areaname= Areanameck= ; abort abend; end; drop areanameck; geocode="&state.-"||cd108; *<---temp override----------------------; %include 'invoke_dovars.sas'/NOsource2; esriid=compress(geocode,'-.'); grcid=esriid; Obs +1; label esriid='Id field to link to ESRI map files' grcid='Id field to link to GRC/MsDIS map files (Mo only)'; label Obs='Observation #'; keep Obs esriid geocode cd108 sumlev areaname state ; keep TotPop -- grcid; run; proc print data=sf3x.&&xx.slds(obs=100); title2 "First 100 Obs from sf3x.&&xx.slds: Complete and Within-County State Legislative Districts"; by SumLev notsorted; id sumlev; var geocode esriid sldcode sldu02 sldl02 areaname totpop; run; proc print data=sf3x.&&xx.sldcos(obs=100); title2 "First 100 Obs from sf3x.&&xx.sldcos: Within-county House and Senate Legislative Districts"; by SumLev State notsorted; id geocode; var esriid grcid sldcode areaname totpop partflag county; format county $5.; run; proc print data=sf3x.&&xx.senate; title2 "sf3x.&&xx.senate"; id Obs; var _char_ totpop; run; proc print data=sf3x.&&xx.house(obs=50); title2 "sf3x.&&xx.house (first 50)"; id Obs; var _char_ totpop; run; proc print data=sf3x.&&xx.cd108; title2 "sf3x.&&xx.cd108"; id obs; var _char_ totpop; run;