x cd /pub/data/acs2013/Tools; %let pgm=create_basetables_varlabs13; filename pgm "&pgm..sas"; *---Earlier we coded and ran cnvt_table_number_lookup.sas to generate the metadata sets Seqtabl1 and Tables1 . Generates table outline metadata modules in the Varlabs directory. Note one of key differences is that with these new meta sets we are going to treat tables with alpha suffixes differently. We want to only generate the tables in Varlabs once with a special note indicating the available suffixes. **We edited this setup 11-25-14 to add the ncellsAlpha variable after realizing that it could differ from the base table size. Rerunning 3-17-15 after fixing a bug in cnvt_table_number_lookup. ; %let year=2013; %let yr=%substr(&year,3,2); %let yearm1=%eval(&year -1); title "&pgm: Generate Variable label txt files in acs&year./basetbls/Varlabs folder"; %let btpath=%str(/pub/data/acs&year./basetbls); libname basetbls "&btpath"; %let bgflag=; /* ========================begin comment==================================== *---We begin by generating the sas attributes for the Variables data sets we are to create. We do this to get consistency with the variable names, types and lengths as established in previous cycles. The output attrib file was edited and included in the conversion steps (macro) below. We changed length of rsfx to $2 to allow keeping value of PR--; libname btabs "/pub/data/acs&yearm1./basetbls"; filename attrib "&btpath./variablesets_attribs.sas"; %*include '/pub/sas/macros/genattr.sas'; %genattr(setin=btabs.variables00_07) ; *--any of the 6 variables datasets would do here--*; run; ==========================end comment====================================== */ %macro doset(set); %let wherec=%str(TopicGrp="&set"); proc sort data=basetbls.tables1(where=( &wherec ) keep=topicgrp bc tableno tabletitle universe alphasfxs nsfxs ncells ncellsAlpha) out=tables1&set ; by tableno bc ; run; proc sort data=basetbls.seqtab1(where=(&wherec and position) ) out=cells1&set; by tableno bc tblsfx position; run; data basetbls.Variables&set(label="Metadata describing table variables on a &set dataset" compress=No); *---Attrib statement(s) generated by genattr macro---; Attrib TableSeqNo length= 4 TableID length=$8 TableName length=$123 Universe length=$120 TableType length=$1 TableNo length=$8 label='5-digit Table #' TableRSfx length=$2 TableCell length= 4 IndentLevel length= 4 Name length=$11 Label length=$64 format=$CHAR. informat=$CHAR. Subject length=$2 TabSet length=$5 NcellsInTable length=$4 nsfxs length= 4 label='# suffix versions of table' AlphaSfxs length=$10 label='Alpha suffixes (A,B,..,I, PR) available for this table' ; keep TableSeqNo--NcellsInTable nsfxs AlphaSfxs ncellsAlpha; *<-----Note----; * length TableSeqNo 4 TableID $8 TableType $1 Tableno $5 TableRSfx $1 Bgflag 3; * The 1s in these set names refer to the fact that these are 1yr tables as opposed to 3 or 5 yr tables--; merge cells1&set (in=invars ) tables1&set (in=intabs ); by tableno bc; if invars; if position=1 then TableSeqNo+1; TableId=tblid; TableName=tableTitle; if Universe=:'Universe: ' then universe=left(substr(universe, 11)); else Universe=Universe; TableType=BC; Tableno=Tableno; TableRSfx=TblSfx; TableCell=position; IndentLevel=IndentLvl; Name=trim(TableID)||'i'||left(put(TableCell,3.)); if indentlvl then label=repeat(' ',indentlvl-1)|| title; else label=title; *<--insert 2 leading blanks per level of indent--; Subject=Topic; TabSet=TopicGrp; if Tblsfx=' ' then NCellsInTable=ncells; else NCellsInTable=ncellsAlpha; *<---new, 11-25-14---; run; proc sort data=basetbls.variables&set ; by TableNo TableType TableRSfx TableCell; run; proc datasets library=basetbls nolist; modify Variables&set; index create tableid; quit; options ls=150; proc print data=basetbls.Variables&set(where=(tablecell=1)); title3 "Listing of basetbls.Variables&set: Table Level Data"; by tabset subject notsorted; id TableId; var TableSeqNo TableType TableNo TableRSfx TableName Universe Ncellsintable ncellsAlpha &bgflag nsfxs; format TableName $60.; run; proc print data=basetbls.Variables&set(obs=200); title3 "Listing of basetbls.Variables&set: Variable Level Data - (first 200 obs)"; by tableID notsorted; id tableID; var tablecell name indentlevel label ; ***format subtitle; format label $char72.; run; *---Finally, we generate the custom txt file that documents the variables within the tables, 1 file per set---; filename varlabs "&btpath/Varlabs/&set.labels.txt"; data _null_; set basetbls.Variables&set end=last; by tableno tabletype; file varlabs; if _n_=1 then put " /* Generated at &systime on &sysdate */ " / 'LABEL '; if first.tabletype then do; put / '/* ' TableID +(-1)'. ' TableName ' */' / '/* Universe: ' universe ' */'; ***if bgflag then put @3 '/* Available at Block Group Level on 5yr Data Sets */' / ; if nsfxs then do; put @3 " /* *** This table is repeated for the following Race/Hispanic/PR suffixes: " AlphaSfxs "*** */"; if ncellsAlpha ne ncellsInTable then put @5 "/* the alpha-suffix versions of this table has fewer cells (" ncellsAlpha ") */" / @5 "/* The A-suffix table cell labels are shown at the end of the cells for this table. */" ; _ncellsInBaseTable=ncellsintable; retain _ncellsinBaseTable; end; _writethisone=1; _firstsfx=tableRSfx; retain _firstsfx; end; length qlabel $260; ****replacing with stmt below 11-25-14. if TableRSfx=_firstsfx then do; if TableRSfx=_firstsfx or (TableRsfx='A' and (ncellsAlpha lt _ncellsInBaseTable)) then do; qlabel=quote(trim(label)); put @5 name @16 "=" qlabel ; end; if last then put ' ;'; run; filename varlabs clear; %mend doset; options mprint; %doset(00_07) ; %doset(08) %doset(09_16) %doset(17_20) %doset(21_24) %doset(25_28) /* ========================begin comment==================================== ==========================end comment====================================== */ *---generate the $itabns format code that is used to look up the number of cells in tables with I suffixes. We use this format in dexter. Coded 9-1-10, jgb---; data format; set basetbls.variables00_07 basetbls.variables08 basetbls.variables09_16 basetbls.variables17_20 basetbls.variables21_24 basetbls.variables25_27; where tablersfx='I'; keep tableid ncellsintable; proc sort; by tableid; data format2; set format; by tableid; if last.tableid; length cellcount $3; cellcount=put(ncellsintable,3.); tableid=substr(tableid,1,length(tableid)-1); keep tableid cellcount; run; proc print data=format2(obs=50); title "format data"; run; filename text '/pub/sas/formats/Sitabns.sas'; libname formats '/pub/sas/catalogs'; %genfmat(fmatname=itabns, sasin=format2, argvars=tableid, arglen=9, library=formats, labelvar=cellcount,labellen=3, other=0, runproc=1);