x cd /pub/data/acs/Tools; %let pgm=variables5yr_finaledit; filename pgm "&pgm..sas"; *---We take the data in latest acs20YY/basetbls/variables5yr data sets and create versions in the btabs5yr subdirectory with same data set names but these will have been edited to insure the variables really exist on our 5yr base data sets and we add a flag to indicate if available at the bg level. ----; %let year=2013; %let yr=%substr(&year,3,2); libname basetbls "/pub/data/acs&year./basetbls" access=readonly; libname btabs5yr "/pub/data/acs&year./btabs5yr"; libname acs&year "/pub/data/acs&year"; %*let tabset=00_07; %macro doit(tabset); *----We look at the tables for the 1yr data vs the 5yr to see differences. It appears some tables are missing in 5yr.---; proc sql; create table tabs1yr as select distinct tableID from basetbls.variables&tabset; proc sql; create table tabs3yr as select distinct tableID from basetbls.variables&tabset._3yr; proc sql; create table tabs5yr as select distinct tableID from basetbls.variables&tabset.5yr; quit; data acs&year..table_differences&tabset; merge tabs1yr(in=in1) tabs3yr(in=in3) tabs5yr(in=in5); by tableId; if not (in1 and in3 and in5); length in1yr in3yr in5yr 3; in1yr=in1; in3yr=in3; in5yr=in5; run; proc print data=acs&year..table_differences&tabset; title "acs&year..table_differences&tabset"; run; %let setname=variables&tabset; %let varlist=; proc contents noprint position data=btabs5yr.usstcnty&tabset out=_contents&tabset(keep=name type varnum); proc sort; by varnum; run; *--the position option did not do this for us (!!??)---; data _null_; set _contents&tabset; where type=1; if substr(name,1,1) in ('C','B'); length varlist $32700; retain varlist; *--This logic assumes the moe vars are all at the end of the obs and we specified position option on proc contents--; if index(name,'m1') then do; call symput("varlist", trim(varlist)); stop; end; varlist=trim(varlist)||' '||name; run; %**put varlist=&varlist; data btabs5yr.&setname; if _n_=1 then do; set basetbls.bgtabsmeta; *---contains single variable bgtabs with a list of bg table names--; *_varlist="%varlist(_numeric_,btabs5yr.usstcnty&tabset)"; retain _varlist "&varlist"; _firstmoe=index(_varlist,'m1'); if _firstmoe then _varlist=substr(_varlist,1,_firstmoe-6); _lenvarlist=length(_varlist); put _firstmoe= _lenvarlist= ; ** _varlist=; retain bgtabs _varlist; drop bgtabs _:; end; set basetbls.&setname.5yr; if length(TableID)>6 then TableRsfx=substr(TableID,7); *---was not always assigned. Can be A, B, ..,I, PR --; *--the variable Name has leading 0s after the "i" item indicator which we edit. B010001i003 should be B01001i3 ; substr(Name,length(name)-2)=left(put(TableCell,3.)); length bg $1; label bg="Available at BG level? (0/1)"; if index(bgtabs,trim(tableID)) then bg='1'; else bg='0'; length NotOK 3; NotOK= (index(TableID,"P")=0) and (Index(_varlist,trim(name))=0); run; proc print data=btabs5yr.&setname (where=(NotOK)); title "Not OK in &setname"; title2 "Not OK Means the Variable Name Was not Found on usstcnty&tabset"; var tableID tablename universe name label; run; %mend doit; %doit(00_07) %doit(08) %doit(09_16) %doit(17_20) %doit(21_24) %doit(25_27) *---Step added and ran interactively 5-7-15---; data acs&year.table_differences; set acs&year..table_differences00_07 acs&year..table_differences08 acs&year..table_differences09_16 acs&year..table_differences17_20 acs&year..table_differences21_24 acs&year..table_differences25_27 ; run;