BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
eb175
Fluorite | Level 6

I found a sample program on the SAS website to import all .csv files from a directory here: https://documentation.sas.com/?docsetId=mcrolref&docsetTarget=n0ctmldxf23ixtn1kqsoh5bsgmg8.htm&docse...

 

I am trying to import several csv files using this macro. The only thing I've changed is the filepath reference when the macro is invoked at the end of the code and I get an error message saying "WARNING: Apparent symbolic reference CSV not resolved." I thought that inputting csv just told the macro what file extension is used for all the files in the folder. I know this warning message is usually the result of trying to use a global variable that has never been defined. I didn't think I was referencing a variable named "CSV." Does anyone know why I might be getting this error? Thanks!

 

%macro drive(dir,ext); 
   %local cnt filrf rc did memcnt name; 
   %let cnt=0;          

   %let filrf=mydir;    
   %let rc=%sysfunc(filename(filrf,&dir)); 
   %let did=%sysfunc(dopen(&filrf));
    %if &did ne 0 %then %do;   
   %let memcnt=%sysfunc(dnum(&did));    

    %do i=1 %to &memcnt;              
                       
      %let name=%qscan(%qsysfunc(dread(&did,&i)),-1,.);                    
                    
      %if %qupcase(%qsysfunc(dread(&did,&i))) ne %qupcase(&name) %then %do;
       %if %superq(ext) = %superq(&name) %then %do;                         
          %let cnt=%eval(&cnt+1);       
          %put %qsysfunc(dread(&did,&i));  
          proc import datafile="&dir\%qsysfunc(dread(&did,&i))" out=dsn&cnt 
           dbms=csv replace;            
          run;          
       %end; 
      %end;  

    %end;
      %end;
  %else %put &dir cannot be open.;
  %let rc=%sysfunc(dclose(&did));      
             
 %mend drive;
 
%drive(c:\temp,csv)
1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @eb175  A quick look makes me spot 

%if %superq(ext) = %superq(&name) %then %do;  /*is this error as the syntax should be %superq(name) without the the ampersand &*/

View solution in original post

4 REPLIES 4
Reeza
Super User

Please show your log, including the error. You may want to add the macro debugging options as well.

 

options mprint symbolgen;
novinosrin
Tourmaline | Level 20

Hi @eb175  A quick look makes me spot 

%if %superq(ext) = %superq(&name) %then %do;  /*is this error as the syntax should be %superq(name) without the the ampersand &*/

eb175
Fluorite | Level 6
That was it - thank you very much!
Reeza
Super User

@SAS_CommAdmin Can you please get this changed in the documentation?

Thanks!

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1844 views
  • 1 like
  • 3 in conversation