*---Access pc sas datasets for the 2004 ACS pums for Mo. As downloaded from AFF site, 3-28-06, jgb. Read data dict CSV files (created from xls file provided) and generate value-label formats, stored in a formats catalog in the acspums library. Running from Windows. ---*; filename pgm 'P:\mcdc\acspums\genfmats.sas'; libname temp 'c:\temp'; libname acspums 'P:\mcdc\acspums'; filename text 'p:\mcdc\acspums\valfmats.sas'; filename datadict ('p:\mcdc\acspums\PUMSDataDict04Hrecs.csv', 'p:\mcdc\acspums\PUMSDataDict04Precs.csv'); /* ========================= *--copy & rename the temp datasets to permanent directory on p: --; data acspums.mohrecs04(label='AFF PUMS data for MO 2004 - Hhld Records data'); set temp.psam_h29; run; data acspums.moprecs04(label='AFF PUMS data for MO 2004 - Person Records data'); set temp.psam_p29; run; ============================ */ proc contents data=acspums.mohrecs04 out=contH(keep=name type where=(type=2)) noprint; run; proc contents data=acspums.moprecs04 out=contP(keep=name type where=(type=2)) noprint; run; data _null_; set contH contP end=last; length cvnames $4000 ; retain cvnames; cvnames=trim(cvnames)||' ' || name; if last then do; put cvnames=; call symput('cvnames',trim(cvnames)); stop; end; run; %put cvnames= &cvnames; *-----Read the data dictionaires with value label info and use to generate a formats catalog.---; data fmtvals; infile datadict missover dsd firstobs=2; length Variable $10 _varlen _start 8 _varlabel $64 Arg $10 ValLabel $80; input Variable -- ValLabel; _PrevLabel=lag(ValLabel); _PrevArg=lag(Arg); flag=0; if indexw("&cvnames",trim(Variable)); *--only keep lines that correspond to character-type vars-; if Variable in ('RT','PUMA','SERIALNO','MSACMSA','PMSA','Variable',' ') then delete; if _start=. then do; *---the label is just a continuation of the previous line. We output the "long" version and set the flag variable which we can use below to delete the previous short version--; Arg=_prevarg; ValLabel=trim(_prevLabel)||' '||ValLabel; flag=1; end; if compress(arg,'b')=' ' then arg=' '; *--lowercase b used to signify a blank in data dict--; drop _:; run; proc sort data=fmtvals; by Variable Arg Flag; run; data fmtvals; set fmtvals; by Variable Arg; if last.Arg; run; *--this keeps the one with flag=1 which has the full label including the continuation text---; %include 'L:\SAS Tools\sasmacro\genfmat.sas'; options NOmprint; %genfmat(setin=fmtvals, argvars=arg,arglen=10, labelvar=ValLabel,labellen=80, fmtnvar=Variable, fmatlib=acspums, runproc=1); *--we did a signon to the mcdc unix env and now we shall upload the datasets and the formats text file, which we then use to create the formats catalog on the unix side--; rsubmit; libname acspums '/pub/data/acspums'; proc upload inlib=acspums outlib=acspums; run; filename vallabs '/pub/data/acspums/vallabs.sas'; proc upload infile=text outfile=vallabs; run; %include vallabs; run; endrsubmit;