title: dropping variables using a macro variable containing list of varnames
body: <p>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.</p>
  
  <p><a href="http://www2.sas.com/proceedings/sugi30/028-30.pdf" rel="nofollow">http://www2.sas.com/proceedings/sugi30/028-30.pdf</a></p>
  
  <p>So i used the following code to make a list in a macro variable:</p>
  
  <pre><code>/*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;
  </code></pre>
  
  <p>I am facing three problems now:</p>
  
  <p>1) When I <code>%PUT &amp;VARLIST</code> , the log displays only 31 of the variables whereas my list is actually 2000+ variables.</p>
  
  <p>2) I don't clearly understand what the statement: <code>trim(left(allvars)) || ' ' || left(_name_);</code> is doing. I know trim removes leading spaces and left is to align left character strings but cannot understand the full statement.</p>
  
  <p>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:</p>
  
  <pre><code>    data inputds2 (drop = &amp;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.
  </code></pre>
  
  <p>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.</p>
  
  <p>EDIT: Tried using another code which is working partially - it makes a bigger list- around 1000 of the 2000+ variables in the &amp;VARLIST macro variable.</p>
  
  <pre><code>data _null_;
  
  set to_drop;
  
  call symput('varlist',trim(
  
  resolve('&amp;varlist')
  
  )||' '||trim(_name_));
  
  run;
  
  %put &amp;varlist;
  </code></pre>