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

I have used the search function to look at other posts but am struggling to find an answer to my problem.

 

I am trying to import all CSV files that exist within a directory using the code found here: https://documentation.sas.com/?docsetId=mcrolref&docsetTarget=n0ctmldxf23ixtn1kqsoh5bsgmg8.htm&docse...

 

%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) 

 

However, I am getting the following error message and cannot figure out where I'm going wrong:  WARNING: Apparent symbolic reference CSV not resolved.

 

The only part of the code I am updating is %drive(c:\temp, csv) to change c:\temp to my directory location where the csv files are located.

 

All the CSV files have the same 5 variables and are in the same format. I am relatively new to SAS, but am hoping to utilize a macro as I have multiple CSV files to combine for several projects. Thank you in advance and please let me know if I can provide additional information. 

1 ACCEPTED SOLUTION

Accepted Solutions
smantha
Lapis Lazuli | Level 10
 %if %superq(ext) = %superq(&name) %then %do; 

should be

 %if %superq(&ext) = %superq(&name) %then %do; 

 

View solution in original post

4 REPLIES 4
smantha
Lapis Lazuli | Level 10
 %if %superq(ext) = %superq(&name) %then %do; 

should be

 %if %superq(&ext) = %superq(&name) %then %do; 

 

ngallagher98146
Calcite | Level 5
Thank you! This fixed the issue.
Tom
Super User Tom
Super User

@smantha wrote:
 %if %superq(ext) = %superq(&name) %then %do; 

should be

 %if %superq(&ext) = %superq(&name) %then %do; 

 


That looks backwards.  The second form is saying that both the EXT and NAME macro variables contain the NAME of the macro variables to be evaluated and macro quoted.  From a quick scan of the code it looks to me like EXT and NAME instead have the actual values that you want macro quote.

%if %superq(ext) = %superq(name) %then %do; 

Although the second call to %SUPERQ() is not needed since we know that the value of NAME is already macro quoted since it was created with the %QSCAN() macro function.

%if %superq(ext) = &name %then %do; 

 

DivyaGadde
Fluorite | Level 6
I still keep getting the same warning even after changing the code.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2161 views
  • 1 like
  • 4 in conversation