*---Access pc sas datasets for the 2005 ACS pums for Mo. As downloaded from AFF site, 04-18-07, jgb. Read data dict CSV file (created using "Save As" from xls file provided) and generate value-label formats, stored in a formats catalog in the acspums library. Running from Windows and uploading results to our Unix site using SAS/Connect. ---*; filename pgm 'P:\mcdc\acspums\genfmats05.sas'; *libname temp 'c:\temp'; libname acspums server=mcdc.mcdcshr; *<---references /pub/data/acspums on mcdc.missouri.edu--; filename text 'p:\mcdc\acspums\valfmats05.sas'; filename datadict 'p:\mcdc\acspums\PUMSDataDict05.csv'; proc contents data=acspums.mohrecs05 out=contH(keep=name type where=(type=2)) noprint; run; proc contents data=acspums.moprecs05 out=contP(keep=name type where=(type=2)) noprint; run; libname acspums clear; *---at this point we reuse acspums to point to windows version--; libname acspums 'P:\mcdc\acspums'; 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 dictionary with value label info and use to generate a formats catalog.---; data fmtvals; infile datadict missover dsd firstobs=2; length _file $8 Variable $10 _varlabel $64 Arg $10 ValLabel $80; input _file 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 arg=' ' 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 (1 or more) 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=acspumsW outlib=acspums; *--write over formats.sas7bcat from 2004--; run; filename vallabs '/pub/data/acspums/vallabs.sas'; *--this set from last yr renamed vallabs04.sas; proc upload infile=text outfile=vallabs; run; *---This module contains line: PROC FORMAT DDNAME=acspums .... followed by VALUE stmts. So it (re)creates acspums.formats catalog.---; %include vallabs; run; endrsubmit; *---And now... upload this program ---; rsubmit; filename unixpgm '/pub/data/acspums/Tools/genfmats05.sas'; proc upload infile=pgm outfile=unixpgm; run; endrsubmit;