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.
%if %superq(ext) = %superq(&name) %then %do;
should be
%if %superq(&ext) = %superq(&name) %then %do;
%if %superq(ext) = %superq(&name) %then %do;
should be
%if %superq(&ext) = %superq(&name) %then %do;
@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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.