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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.