I use this code to input CSV files data into SAS:
%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))"
dbms=csv
replace
out=dsn&cnt
;
run;
%end;
%end;
%end;
%end;
%else
%put &dir cannot be open.;
%if &did %then %let rc=%sysfunc(dclose(&did));
%mend drive;
%drive(C:path\to\folder\,csv)
but it names the datasets as dsn1, dsn2 etc while I want to have the name of the file (without the CSV part) as the dataset name. How can I do that?
%superq()
function wrong. It wants the name of the macro variable to quote, not the value to quote. – TomEXT=csv
then the%superq(&ext)
expression is going to quote the value of the undefinedCSV
macro variable. – Tom