x cd /pub/data/pums2000/Tools; %let pgm=gen_Variables; filename pgm "&pgm..sas"; *----Generate the pums2000.Variables dataset with metadata re the pums2000 datasets. John Blodgett, OSEDA, U. of Missouri Outreach & Extension Under contract with the Missouri Census Data Center. Oct. 2003 ----*; title "&pgm : Generate Metadata Sets for pums2000 filetype"; libname pums2000 '/pub/data/pums2000'; libname user '/SAS_temp/user'; %let stab=mo; %let keep=name type length varnum label format ; /*<=========================Comment out===================================== proc contents data=pums2000.&stab.hrecs1 noprint out=ch1(keep=&keep); run; proc sort; by name; run; proc contents data=pums2000.&stab.hrecs5 noprint out=ch5(keep=&keep); run; proc sort; by name; run; data hrecvars; merge ch1(in=in1) ch5(in=in5); by name; length sample $1; *--a value of 1 or 5 says variable is only in that sample. Otherwise 'b' means it is in both the 1 pct and 5 pct sample sets.--; if not in1 then sample='5'; else if not in5 then sample='1'; else sample='b'; label sample='In which sample(s)?'; run; proc contents data=pums2000.&stab.precs1 noprint out=cp1(keep=&keep); run; proc sort; by name; run; proc contents data=pums2000.&stab.precs5 noprint out=cp5(keep=&keep); run; proc sort; by name; run; data precvars; merge cp1(in=in1) cp5(in=in5); by name; length sample $1; *--a value of 1 or 5 says variable is only in that sample. Otherwise 'b' means it is in both the 1 pct and 5 pct sample sets.--; if not in1 then sample='5'; else if not in5 then sample='1'; else sample='b'; label sample='In which sample(s)?'; run; ===========================End commented out================================ */ data pums2000.Variables(label='Metadata for PUMS datasets'); length VarCat $3 TypeLen $4 aflag 3 ; set hrecvars precvars(in=inp); by name; if first.name then do; if not last.name then do; VarCat='key'; retain varcat; delete; end; else VarCat=' '; end; if VarCat=' ' then if inp then VarCat='p'; else VarCat='h'; if type=2 then TypeLen='$'||left(put(length,3.)); else TypeLen='n'||put(length,1.); if scan(label,-2,' ')='Allocation' and scan(label,-1,' ')='Flag' then VarCat=trim(varcat)||'af'; aflag=(substr(varcat,2,2)='af'); *--so value of VarCat can be: key - one of the 3 key vars, state, puma1 and serialno on both hrecs and precs datasets. p, h - a non-allocation variable on either the precs or hrecs set, respectively. afp, afh - an allocation flag variable on either the precs or hrecs set, respectively. --*; *---Check to see if we have a SAS format code with a name that indicates it goes with this variable. If so, we assing a value to format. We may have to do some manual overrides of this later.---; if not aflag then do; length _fcatname $40; if type=2 then _etype='formatc'; else _etype='format'; _fcatname='pums2000.formats1.'||trim(name)||'.'||_etype;; if cexist(_fcatname) then do; if type='2' then format='$'||name; else format=name; end; else if index('123456789',trim(substr(name,length(name),1))) then do; *--the variable name ends with a digit. In these cases we typically just added a trailing underscore to create the format name.--; length _altname $9; _altname=trim(substr(name,1,Length(name)-1))||'_'; _fcatname='pums2000.formats1.'||trim(_altname)||' '||_etype;; if cexist(_fcatname) then do; if type=2 then format='$'||_altname; else format=_altname; end; end; *--numeric suffix var processing--; end; *--not aflag do group--; drop _: ; drop type length; run; proc sort data=pums2000.Variables; by VarCat varnum; run; proc print data=pums2000.Variables; by VarCat; id name; title2 'Listing of pums2000.Variables Dataset'; run; *----Run some test freq tables using new variables with names indicating they are different on the 5 pct sample but using the old 1 pct sample format codes.----; options fmtsearch=(pums2000.formats1 sasctlgs work); proc freq data=pums2000.moprecs5(keep=ancfrst5 ancscnd5 lang5 pob5 migst5 powst5 occcen5 occsoc5); format anc: $ancst1_. lang5 $lang1_. pob5 migst5 powst5 $stctry1_. occcen5 $occcn1_. occsoc5 $occsc1_.; *weight pweight; table occsoc5; run;