I will explain so maybe you can work out the issue you have. First I create some data to work with. data foo; input dte $ mgf3654 emtcol1 ntd8475 col3; cards; 2001.01 5 0 23 45 2001.02 89 0 4 2 2006.12 12 0 8 6 ; run; I have a character field (dte) and four numeric variables without a standard naming convention (mgf3654 emtcol1 ntd8475 col3). The first thing I want to do is collect the metadata I want to work with. data _null_; length names nsums $32000; retain names nsums; set sashelp.vcolumn(where=(libname='WORK' and memname='FOO' and type='num')) end=eof; names=catx(' ',of names name); nsum=strip(name) || '_sum'; nsums=catx(' ',of nsums nsum); if eof then do; call symputx('names',names); call symputx('nsums',nsums); call symputx('vars',put(_n_,best.)); end; run; I will collect, dynamically the names of my numeric variables. I will create a second copy of these names with '_sum' added to them for a calculation step next. I will collect the number of variables I'm working with into macro variable 'vars' Now I will run a sum for all columns. If the columns sum is 0 then I will want to drop that variable. data _null_; set foo end=eof; array v &names; array s &nsums; do i=1 to &vars; s+v; end; length drops $32000; retain drops; if eof then do; do i=1 to &vars; if s=0 then do; drop=scan("&names",i,' '); drops=catx(' ',of drops drop); end; end; call symputx('drops',drops); end; run; Create arrays using the variable lists I collected in the previous step The first loop will calculate the sums for each column When I reach the last record in the file I will loop through each variable again. If I have calculated this columns sum to be 0 I will collect the name of the variable into a macro variable 'drops' to use later. Now that I have found all the variables I want to drop I will perform the action. proc sql noprint; alter table foo drop column &drops; quit;
... View more