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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1830 views
  • 1 like
  • 4 in conversation