x cd /pub/data/stf803x2/Tools; %let pgm=cnvtallstates_stf803x2; filename pgm "&pgm..sas"; /*---Access 1980 stf3 datasets and create standard extract datasets for all states in the U.S.--; Ion Gireada, John Blodgett, OSEDA Under contract with the Missouri Census Data Center. Feb. 2006 ---*/ libname stf803 "/pub/data/stf803" access=readonly; libname stf803x2 "/pub/data/stf803x2"; %let filetype=stf803x2; title "&pgm: Create stf803x2 Extract Datasets from stf803 Complete Table Datasets"; %global Pctof table curtable curtabno dvmode; %let curtabno=0; %let reftables=; %let dvmode=data; %macro cnvtmeta(mode,moregeos=,setin=,setout=,sumlevs=,drop=); %global dvmode; %let dvmode=&mode; %*----------macro has been edited for this app so that meta mode not applicable! ---; %if &setout=%str() %then %let setout=&setin; %*--we use &settype to distinguish between inventory (i) or hierarchal (h) sets. We use this to be select about geography processing.--; %if &sumlevs = %str() and %length(&setin)=3 %then %do; %If %substr(&setin,3,1)=i %then %let sumlevs=040 050 060 160 500; %If %substr(&setin,3,1)=h %then %let sumlevs=070 082 090 16 ; %end; %if &dvmode = %str(data) %then %do; *---------Here is the conversion data step-------------*; data stf803x2.&setout ; length geocode $32 slvl $3; length default=5; set stf803.&setin; %if %superq(sumlevs) ne %str() %then %do; where index("&sumlevs",trim(sumlev)) gt 0; %end; *retain geocomp '00'; *if geocomp in(' ','00'); *--so even if not on the input set (which it usually is not) this works--; retain _val .; if SumLev=' ' then SumLev=slvl; else if slvl=' ' then slvl=SumLev; fipco=county; * rename fipsmcd=cousubfp fipsplac=placefp; select(SumLev); *---Assign the standardized Geographic Code to uniquely ID the geographic area--; %if %index(&sumlevs,05) %then %do; when('05') do; geocode=scsa; end; %end; %if %index(&sumlevs,06) %then %do; when('06') do; geocode=%concatd(scsa,state); end; %end; %if %index(&sumlevs,07) %then %do; when('07') do; geocode=smsa; end; %end; %if %index(&sumlevs,08) %then %do; when('08') do; geocode=%concatd(smsa,state); end; %end; %if %index(&sumlevs,010) %then %do; when('010') do; geocode=' '; *,--no code for US totals--; end; %end; %if %index(&sumlevs, %str(16)) %then %do; when('16') do; geocode = %concatd(county,ed); end; %end; %if %index(&sumlevs,020) %then %do; when('020') do; geocode=region; end; %end; %if %index(&sumlevs,030) %then %do; when('030') do; geocode=division; end; %end; %if %index(&sumlevs,040) %then %do; when('040') geocode=state; %end; %if %index(&sumlevs,050) %then %do; when('050') geocode=county; %end; %if %index(&sumlevs,060) %then %do; when('060') do; geocode=%concatd(county,fipsmcd); end; %end; %if %index(&sumlevs,070) %then %do; when('070') do; geocode=%concatd(county,fipsmcd,fipsplac); end; %end; %if %index(&sumlevs,082) %then %do; when('082') do; geocode=%concatd(county,fipsmcd,fipsplac,tract); end; %end; %if %index(&sumlevs,090) %then %do; when('090') do; geocode=%concatd(county,mcd,place,tract,urbarurl,blkgrp); end; %end; %if %index(&sumlevs,160) %then %do; when('160') do; geocode=%concatd(state,fipsplac); end; %end; %if %index(&sumlevs,400) %then %do; when('400') do; geocode=urbarea; end; %end; %if %index(&sumlevs,410) %then %do; when('410') do; geocode = %concatd(urbarea,state); end; %end; %if %index(&sumlevs,500) %then %do; when('500') do; geocode=%concatd(state,condist); end; %end; %if %index(&sumlevs,871) %then %do; when('871') do; geocode=zip; end; %end; %if %index(&sumlevs,881) %then %do; when('881') do; geocode=%concatd(zip,county,smsa); end; %end; otherwise delete; end; %end; %else %if &dvmode=%str(meta) %then %do; *------Here is the data step that generate sf3x.Variables when dvmode=meta-----------; data stf803x2.Variables(label="Meta data describing the variables on these datasets"); %attrmeta ; retain Year '1980'; *<===================; retain Source 'Summary File 3, 1980 Census'; *<===============; %end; %else %put ***** dvmode parm value not recognized: value= &dvmode ; %include '/pub/data/stf803x2/Tools/invoke_dovars.sas' / NOsource2; %if &dvmode=%str(data) %then %do; Obs+1; keep geocode sumlev slvl state fipco county areaname ed fipsmcd fipsplac tract mcd place urbarurl blkgrp division &moregeos; keep smsa placesze placdesc partplac psad sumrylvl ; keep TotPop -- Obs; drop _val ; %if %nrbquote(&drop) ne %str() %then %do; drop &drop ; %end; run; %end; %else %if &dvmode=%str(meta) %then %do; *-----meta processing-----------------------------; run; options nonumber nodate orientation=landscape nocenter; ods printer pdf file="../Variables.pdf" ; ods path work.templat(update) sashelp.tmplmst(read); proc template; %include '/pub/sascode/osedablue.sas'; *<====Optional style thing===; run; ods html file='../Variables.html' style=osedablue; ods listing close; proc print data=stf803x2.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; title 'Metadata for the stf803x2 Filetype (Partial listing of Variables dataset)'; footnote 'Note: If Universe Variable has a value then there is a corresponding Pct Variable'; footnote2 'Example: PctWhite is defined and is 100*White/TotPop'; run; ods printer close; ods html close; %end; %mend cnvtmeta; options nomprint; title2 "Revised as of &sysdate &systime"; /* =======================Begin comment================ %cnvtmeta(meta,setin=dei); %cnvtmeta(data,setin=dei); %cnvtmeta(data,setin=deh); %cnvtmeta(data,setin=cti); %cnvtmeta(data,setin=cth); ======================End comment================== */ %macro doit(state,stab); %cnvtmeta(data,setin=&stab.i,drop=ed urbarurl); %cnvtmeta(data,setin=&stab.h); %mend doit; %dostates(n=51); %***dostates(29) ; /* =======================Begin comment================ %cnvtmeta(data,setin=usplaces,sumlevs=160,drop=county fipco smsa mcd fipsmcd ed); %cnvtmeta(data,setin=uszips,sumlevs=871 881); %cnvtmeta(data,setin=usmisc,sumlevs=010 020 030 05 06 07 08 400 410,drop=county fipco mcd psad); %cnvtmeta(data,setin=usmcds11,sumlevs=060,drop=plac: partplac condist fipsplac); ======================End comment================== */ %cnvtmeta(data,setin=usstcnty,sumlevs=040 050,drop=mcd place fipsmcd fipsplac partplac plac: urbarurl);