title: SAS libref not recognized in macro loop
body: <p>I've run into an odd SAS quirk that I can't figure out - hopefully you can help. </p>
  
  <p>I have a simple macro loop that imports CSV files and for some reason if I use a libref statement in the "out=" part of the import procedure, SAS doesn't recognize the libref as a valid name. But if I use the same libref in a data step, it works just fine. </p>
  
  <p>The specific error it gives is: "ERROR: "TESTDB." is not a valid name."</p>
  
  <p>I'd like to figure this out because I work with pretty big files and want to avoid reading through them more times than is necessary. </p>
  
  <p>Here's the code that works, with some comments in it. I got around the issue by reading in the files, then writing them to permanent SAS datasets in a second step, but ideally I'd like to import the files directly into the "TESTDB" library. Any idea how to get SAS to recognize a libref in the "out=" statement of the import procedure?</p>
  
  <pre><code>libname testdb "C:\SAS test"; 
  %let filepath = C:\SAS test\;
  
  %macro loop(values); 
      %let count=%sysfunc(countw(&amp;values)); 
      %do i = 1 %to &amp;count; 
          %let value = %qscan(&amp;values,&amp;i,%str(,));
          proc import datafile = "&amp;filepath.&amp;value..csv" 
              out = &amp;value dbms=csv replace; getnames=yes;
                       /*"out=testdb.&amp;value" in the line above does not work*/
          run; 
          data testdb.&amp;value; set &amp;value; run; 
                   /*here the libref testdb works fine*/
      %end; 
  %mend; 
  %loop(%str(test_a,test_b,test_c)); 
  </code></pre>
  
  <p>Thanks in advance for your help! </p>
  
  <p>john</p>