Total beginner at SAS. I wanted to drop a list of variables from my inputds. This list itself is present as observations in another dataset. After doing some googling, I found this excellent paper on the topic.
http://www2.sas.com/proceedings/sugi30/028-30.pdf
So i used the following code to make a list in a macro variable:
/*make a list of variables as a macro variable */
data _null_;
length allvars $1000;
retain allvars ' ';
set to_drop end=eof;
allvars = trim(left(allvars))||' '||left(_name_);
if eof then call symput('varlist', allvars);
run;
I am facing three problems now:
1) When I %PUT &VARLIST
, the log displays only 31 of the variables whereas my list is actually 2000+ variables.
2) I don't clearly understand what the statement: trim(left(allvars)) || ' ' || left(_name_);
is doing. I know trim removes leading spaces and left is to align left character strings but cannot understand the full statement.
3) Then I try to drop it from my inputds using the following code, I get a warning message and the drop doesn't happen:
data inputds2 (drop = &varlist);
set inputds;
run;
WARNING: The variable avg_weighted in the DROP, KEEP, or RENAME list has never been referenced.
NOTE: There were 43662 observations read from the data set WORK.INPUTDS.
NOTE: The data set WORK.INPUTDS2 has 43662 observations and 3465 variables.
In reality my variable name reads like : avg_weighted_minutes_view_3739 avg_weighted_minutes_view_7963 avg_weighted_minutes_view_(XXXX) The last 4 digits are random. The are SAS generated names since my labels contain spaces.
EDIT: Tried using another code which is working partially - it makes a bigger list- around 1000 of the 2000+ variables in the &VARLIST macro variable.
data _null_;
set to_drop;
call symput('varlist',trim(
resolve('&varlist')
)||' '||trim(_name_));
run;
%put &varlist;