x cd /pub/data/acs2010/Tools; %let pgm=create_basetables_varlabs10; filename pgm "&pgm..sas"; *---We used to do a lot more in a comparable setup here. But the creation of the metadata sets (basetbls.variablesXXXXX) is now handled by Billy Earney using scripts stored elsewhere.---; *--In Sept 2011 we just copied the acs2009/Varlabs folder to the correponding 2010 folder. So the labels were not really 2010, but 2009 vintage. But in 9/12 we regenerated the basetbls.variables data sets for 2010 so we can now regenerate these metadata files; %let year=2010; title "&pgm: Generate Variable label txt files in acs&year./basetbls/Varlabs folder"; %let btpath=%str(/pub/data/acs&year./basetbls); libname basetbls "&btpath"; libname temp "&btpath./temp"; *---we moved the variables**** sets as transferred to this temoorary location to allow us to update them and store the edited versions in the basetbls directory with the same set names-; filename csvbgs "&btpath./5_year_detailed_tables.csv" ; *---Create a metadata set with the IDs of those tables avaialbe at the BG level. We read a CSV file created from an xls file downloaed from Bureau web site.---; options msglevel=i; data basetbls.bgtabs(label='IDs of tables available at the BG level'); infile csvbgs dsd truncover firstobs=2 termstr=crlf; length TableID $8 TableTitle $128 bgflag 3 Topic $2 _field3 $8 _bgflagin $6; input TableID TableTitle _field3 _bgflagin; if _n_ le 10 then put tabletitle= _bgflagin=; if tableID=' ' then stop; Topic=substr(TableID,2,2); bgflag= (_bgflagin ne ' '); drop _: ; run; proc sort; by TableId; run; *proc freq data=basetbls.bgtabs; *table Topic bgflag; * run; %macro doset(set); %*---This macro edits 1 of the variables datasets. It merges the bgtabs info and redefines the TableNo variable so it is just the 5-character numeric portion of the tableID. So if ID id c27001B then TalbeNo us just 27001. The formula is TableId=Tabletype||tableNo||tablersfx --------; proc sort data=temp.variables&set; by tableid TableCell; run; data basetbls.Variables&set(label="Metadata describing table variables on &set dataset" compress=No); length TableSeqNo 4 TableID $8 TableType $1 Tableno $5 TableRSfx $1 Bgflag 3; merge temp.variables&set (in=invars drop=Tableno) basetbls.bgtabs(in=inbgs keep=tableid bgflag); by tableid; if invars; *---Edit TableNo variable---; Tableno=substr(tableid,2,5); 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 bgflag; 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 tableID notsorted; file varlabs; if _n_=1 then put " /* Generated at &systime on &sysdate */ " / 'LABEL '; if first.tableid then do; put / '/* ' TableID +(-1)'. ' TableName ' */' / '/* Universe: ' universe ' */'; if bgflag then put @3 '/* Available at Block Group Level on 5yr Data Sets */' / ; end; length qlabel $260; qlabel=quote(trim(label)); put @5 name "=" qlabel; 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_27) *---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);