x cd /pub/data/sf32000x/Tools; %let pgm=cnvtsf3x2; filename pgm "&pgm..sas"; /*---Access Census 2000 full sf3 datasets and create standard extract datasets and/or metadata (Variables) dataset. Input filetype is sf32000, output filetype is sf32000x. This is just an ALTERNATE DRIVER SETUP to convert specific files. Most converts done in cnvtsf3x.sas setup. *<=== USING 9-28-02 to convert the Delaware data. *<=== Using 7-13-05 to convert the Nebraska data. rerun 11-20-09 after fix to disabled65 variable. Real work is mostly done in the included file invoke_dovars.sas . ---*/ %global temp; *--set this parm to a value of %str(/temp) when reading and writing from the temp subdir (embargoed)-; %*let temp=%str(/temp); %let temp=; %let dvmode=data; %*--the "dovar mode" global parm controls what kind of output is generated by the dovar macro. The values are data or meta, which cause it to either generate actual conversion data step code or code to create metadata set Variables. The value is also looked at by smaller macros which generate the start and end of the data steps during which the dovar macro invocations take place. --*; title "&pgm: Create sf32000x Extract Datasets from sf32000 Datasets"; %global pctof table curtable curtabno dvmode; %let curtabno=0; *----the dovar macro is where the work is actually done. Below, the cnvtmeta macro serves as the "driver" which invokes this macro one per variable. It gets run once in data more and once in meta mode--; %include '/pub/sasmacro/dovar.sas'; *---contains the dovar macro-------------------; %macro cnvtmeta(mode); libname sf3 "/pub/data/sf32000&temp" access=readonly; libname sf3x "/pub/data/sf32000x&temp"; %global setin dvmode; %let setout=&setin; *--by default we use the input set name base as name of output set--; %let dvmode=&mode; %if &dvmode = %str(data) %then %do; *---------Here is the conversion data step-------------*; data sf3x.&setout.i sf3x.&setout.h sf3x.&setout.stcnty; length default=5 Obs 5 esriid $16; merge sf3.&setin.ph sf3.&setin.phct(in=inct); by logrecno; where geocomp='00'; ************Too confusing to keep *************; esriid=compress(geocode,'-.'); label esriid='Id field to link to ESRI map files'; %end; %else %if &dvmode=%str(meta) %then %do; *------Here is the data step that generate sf3x.Variables when dvmode=meta-----------; data sf3x.Variables(label="Meta data describing the variables on these datasets"); attrib Name label='Variable Name' length=$32 Label length=$80 format=$char. Definition length=$200 label='Definition - Code used to derive' Comment length=$400 Format length=$16 TypeLen length=$8 label='Variable type and length' Universe length=$64 UnivVar length=$32 label='Universe Variable' WtVar length=$32 label='Weight Variable' Lvl length=3 label="Data Indent Level" Display length=3 label="Display in std report?" PctFlag length=3 label='Pct Variable Flag' Table length=$64 TableNo length=3 label='Table #' Keywords length=$80 Year length=$4 Source length=$40 RefTables length=$40 label='Related Table(s)' ; *** OtherYears label='Other Years Available' length=$32; retain Year '2000'; retain Source 'Summary File 3, 2000 Census'; %end; %else %put ***** dvmode parm value not recognized: value= &dvmode ; options NOmprint; %include 'invoke_dovars.sas'; %*<----this module does the work of assigning the global parms and invoking the dovars parm for each variable on the dataset. Which means this module (cnvtsf3x.sas) does not really define what sf32000x is, it is this included module that really does it. ----; %if &dvmode=%str(data) %then %do; label grcid='Id field to link to GRC/MsDIS map files (Mo only)'; if state='29' and geocode=:'29' then grcid=substr(esriid,3); if sumlev in ('040','050','060','140','150','155','160','170','280','230','374', '390','395','420','431','500','851','852','871','881') then do; _iobs+1; Obs=_iobs; output sf3x.&setout.i; if sumlev in ('040','050') then output sf3x.&setout.stcnty; end; else if not (sumlev=:'5') then do; _hobs+1; obs=_hobs; output sf3x.&setout.h; end; keep Obs esriid geocode sumlev areaname logrecno esriid grcid state county msacmsa ua tract zcta5; keep TotPop -- grcid; label Obs='Observation #'; drop _iobs _hobs; run; *----Create 3 views for places, tracts and zipcodes----; proc sql; create view sf3x.&setout.tracts as select * from &setout.i where sumlev='140'; create view sf3x.&setout.bgs as select * from &setout.i where sumlev='150'; create view sf3x.&setout.places as select * from &setout.i where sumlev='160'; create view sf3x.&setout.zips as select * from &setout.i where sumlev='871'; create view sf3x.&setout.msas00 as select * from &setout.i where sumlev='390'; quit; %end; %else %if &dvmode=%str(meta) %then %do; *-----meta processing-----------------------------; run; options nonumber nodate orientation=landscape nocenter; ods printer pdf file="../Variables.pdf" ; ****orient=landscape; /* proc template; %include '/pub/sascode/osedablue.sas'; *<====Optional style thing===; run; */ ods html file='../Variables.html' contents='../VariablesContent.html' style=osedablue; ods listing close; proc print data=sf3x.Variables label; where pctflag=0 or UnivVar=' '; *<--do not show the Pct variables unless they are stand-alone--; by table notsorted universe notsorted; id name; var label--comment UnivVar WtVar; format label $char.; title 'Metadata for the sf32000x Filetype (Partial listing of Variables dataset)'; footnote 'Note: Universe Variable is denominator used to create corresponding Pct Variable'; title2 "Revised as of &sysdate &systime"; run; ods printer close; ods html close; %end; libname sf3 clear; libname sf3x clear; %mend cnvtmeta; %let setin=de; %let temp=; %cnvtmeta(data); %let setin=ne; %let temp=; %*cnvtmeta(meta) ; %cnvtmeta(data) ; run;