I am using SAS University edition .
I have placed the 2 CSV files with different name in the same "my folder" and I want it to be imported to sas. I am trying to create macros for importing multiple csv or xls files .
my location of the file is "/folders/myshortcuts/myfolder/DS1"
Please suggest as to which part of the code is wrong ?
I have tried the below code but I am getting the error .
Code
%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(/folders/myshortcuts/myfolder/DS1,csv)
Error in LOG
Change the PROC IMPORT line to use &dir/%qsysfunc, instead of &dir\%qsysfunc.
proc import datafile="&dir/%qsysfunc(dread(&did,&i))" out=dsn&cnt
Change the PROC IMPORT line to use &dir/%qsysfunc, instead of &dir\%qsysfunc.
proc import datafile="&dir/%qsysfunc(dread(&did,&i))" out=dsn&cnt
thanks for your prompt reply it works perfectly
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 25. 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.