x cd /pub/data/sf12000/Tools; %let pgm=genVariables; filename pgm "&pgm..sas"; *****************NEEDS FURTHER WORK. Input dictionary file formats differ significantly from the sf3 versions that we read with the corr. program in the sf32000 Tools lib. *************************************; *--Generate the 3 meta-data sets sf1.VariablesPH, VariablePHCT and VariablesPCT12R from a proc contents dataset and from parsing the text in the 3 XXXLabels.sas modules as created by Roy Williams. The latter is used to get things like table names, universes, indent level, etc. jgb, 1/03 --*; libname sf1 '/pub/data/sf12000'; libname user '/SAS_temp/user'; options mprint; %macro doset(set); filename datadict "../Varlabs/&set.labs.sas"; %let upset=%upcase(&set); *-- Extract metadata from a sample sf1 data set. Here we get the variable name, label, type and length.--; proc contents data=sf1.mo&set out=contents&set(keep=varnum type formatd formatl name label) noprint; run; proc sort data=contents&set; by varnum; where type=1; run; data vars&set; set contents&set; where varnum ge 71; *--ignores id variables--; length TableID $8 TableName $240 Universe $140 TableType $3 TableNo 3 TableRSfx $1 TableCell 3 IndentLevel 3; label TableRSfx='Table Racial Suffix letter'; retain; length _id $8 _norsfx $6; _id=scan(name,1,'i'); TableCell=scan(name,2,'i'); _id=upcase(_id); *<----------unlike sf3 the sf1 table ids were in lower case!--; if _id not in: ('P', 'H') then delete; _nvar+1; if _id ne TableID then do; *--We have a new table. Read the info from the data dictionary ( sas labels) file-; _ntable+1; _ix=0; infile datadict end=eofdd; do until (_ix); link gethdr; _ix=index(_infile_,trim(_id)||'. '); *--e.g. look for "P12. "--; end; *<----; put 'Hdr found for ' _id ; TableID=_id; TableName=substr(_infile_,_ix); _ix2=verify(_id,'PHCTABCDEFGHI'); *--look for first non-alpha, i.e where the number starts-; TableType=substr(_id,1,_ix2-1); _norsfx=substr(_id,_ix2); _l=length(_norsfx); if verify(substr(_norsfx,_l,1),'1234567890') then do; TableNo=substr(_norsfx,1,_l-1); TableRSfx=substr(_norsfx,_l,1); end; else do; TableNo=_norsfx; TableRSfx=' '; end; **TableName=substr(TableName,1,length(TableName)-2); *--remove the trailing '*-/'--; length _restoflabel $72; if substr(TableName,length(TableName),1) ne ']' then do; *--label is continued-; put '*temp* Looking for continued table name **' tablename=; _looking=1; readnext: link gethdr ; _restoflabel=left(_infile_); ****left(substr(_infile_,3)); *--removes leading '/-*'--; _ncycle+1; if _ncycle gt 1500 then do; put '***ERROR!! Too many extra cycles -- check logic ***** '; stop; *<---; end; TableName=trim(TableName)||' | ' || _restoflabel; put '+++' _restoflabel=; ***if substr(TableName,length(TableName),1) ne ']' then goto readnext; if index(TableName,']')=0 then goto readnext; if substr(TableName,length(TableName),1) ne ']' then do; _ix=index(TableName,']'); if _ix then substr(TableName,_ix)=' '; *--remove anything after dimensions-; end; end; _looking=0; *--now read the line with the universe for the table--; finduniv: link gethdr; _ix=index(_infile_,'Universe: '); put '+++' _infile_ '+++' _ix= _li= _ib= _inlineno=; if _ix=0 then do; if index(_infile_,'decimal') then goto finduniv; put /'*** ERROR *** Keyword "Universe:" not found on data dict file with table= ' TableName; _nerr+1; end; else do; Universe=substr(_infile_,_ix+10); *--we lose portions of value that go on to another line-; do until (_infile_ eq ' '); *--look for continuation of universe--; link gethdr; if _infile_ ne ' ' then Universe=trim(Universe)||' '||left(substr(_infile_,3)); end; end; end; *---processing new table--; *--Determine indentation level by counting leading blanks in the variable label. Each 2 blanks represents one level of indentation. But there are some special considerations: first line of table has one blank and all others are indented 5 extra spaces in addition to 2 per level--; _ix=verify(label,' '); if _ix <=2 then IndentLevel=0; else IndentLevel=(_ix -6)/2; *--we use 5 here instead of 1 to account for extra 5 indented spaces on sf1 dd--; if IndentLevel lt 0 or IndentLevel ne int(IndentLevel) then put '***error*** Bad indent level: ' label= _ix= indentlevel=; return; gethdr: get1: input; _inlineno+1; put '***' _infile_ '***'; if _infile_=' ' then return; *<--logic requires we see blank lines--; _li=length(_infile_); if _li lt 2 then goto get1; if not _looking then if substr(_infile_,1,2) ne '/*' and substr(_infile_,1,2) ne 'Un' then goto get1; *--return header lines only--; if substr(_infile_,_li-1,2)='*/' then _infile_=substr(_infile_,1,_li-2); *--remove trailing '*-/'--; _ib=index(_infile_,']'); if 0 < _ib < _li then substr(_infile_,_ib+1)=' '; *--truncate after right bracket-; return; drop _: type; run; proc sort data=vars&set out=sf1.Variables&upset(label="Metadata describing table variables on &upset dataset" index=(TableID) compress=yes); ***Change this sort order 11-14-02, jgb: by TableID; by TableType TableNo TableRSfx TableCell; run; proc datasets library=sf1 nolist; modify Variables&upset; index create tableids=(TableType TableNo TableRSfx); quit; proc print data=sf1.Variables&upset; title3 "Listing of sf1.Variables&upset"; by TableType TableNo TableRSfx TableName ; format TableName $60.; run; %mend doset; %doset(ph) %doset(pct) %doset(pct12r)