x cd /pub/data/acs2010/Tools; %let pgm=cnvt_vars_2006_2010; filename pgm "&pgm..sas"; *---Read the variable defns code for 2006-2010 5-yr acs profile variables to corresponding SAS code. We esp want to use results as starter set to generate a new bg profile that will only have items available at the block group level. jgb, 4-14-12. ---*; filename in "vars_acs_2006_2010.txt"; libname user '/SAS_temp/userb'; libname acs2010 '/pub/data/acs2010'; data metavars5; infile in dsd dlm='09'x lrecl=1200 firstobs=2 ; ** obs=20; length _appname $25 varname $31 subject_group $16 TableName $64 Universe $64 _def _defmoe $512; input _appname -- _defmoe; *---Parse the definition and create a SAS version.---; length _left $32 _op $1 _right $512; length Definition $200; _defin=_def; _start=1; do until (_right=' '); link splitit; if _start then do; _start=0; definition=catt(_left,_op); end; else definition=catt(definition,_left,_op); end; TooLong=' '; if length(definition) gt 100 then TooLong='YES'; if _n_ le 5 then put / _all_; output; return; splitit: *---splits the current _def string into 3 pieces: left operand (_left), operator (_op) and right operatnd (_right). It also does parsing of the _left operand so that it is translated from mySQL syntax to our SAS variable naming convention. E.g. it converts E01.B01001i001 to B01001i1 ---; _ix=indexc(_def,'+-/*'); if _ix=0 then do; _left=_def; _right=' '; _op=' '; _def=' '; end; else do; _op=substr(_def,_ix,1); _left=substr(_def,1,_ix-1); _right=substr(_def,_ix+1); _def=_right; end; _idot=index(_left,'.'); if _idot then _left=substr(_left,_idot+1); *--so E01.B01001i003 becomes B01001i003--; _ii=index(_left,'i'); if _ii then do; length _cell $3; _cell=substr(_left,_ii+1); *--remove leading 0s from the cell (item) # -; if substr(_cell,1,2)='00' then _cell=substr(_cell,3,1); else if substr(_cell,1,1)='0' then _cell=substr(_cell,2); _left=substr(_left,1,_ii-1)||'i' ||_cell; end; return; drop _: ; run; options ls=150; proc print data=metavars5 (obs=50); id varname; format definition $64.; var definition subject_group--Universe ; run cancel; proc print data=metavars5 (where=(TooLong='YES')); by toolong; id varname; title "Definitions Longeer than 100"; run;