Hi,
I am trying to import all csv files under a folder using macro. I want to keep the original file name. (for example: original file name: data11.csv importedsas data file name: data11 .
I find following macro program can import the files, my question is how can modify it to retain the original file name rather than generate a new name.
The macro I find on line:
%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 /*this is name part I want to change*/ 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)
That's a duplicate with answers already here:
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.