Hi all,
I am trying to import multiple csvs, from multiple folders, where the folder name increments by 1 each day. Is there a way I can import multiple CSVs where the folder each day increments by 1?
For ex:
Day1 = C:temp\00001
Day = C:temp\00002
end ex:
I found a macro that will import multiple CSVs from the same directory but I can't figure out how to import from multiple directories
code below to pull all CSV from same dir....
%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\_20191101-000031,csv)
code below to try and add pull from multiple dir at same time....
%macro test;
%do i = 30 %to 31;
%drive("C:temp\-0000&i,csv");
%end;
%mend;
%test
Hello @zdeb15,
Your question requires more details before experts can help. Can you revise your question to include more information?
Review this checklist:
To edit your original message, select the "blue gear" icon at the top of the message and select Edit Message. From there you can adjust the title and add more details to the body of the message. Or, simply reply to this message with any additional information you can supply.
SAS experts are eager to help -- help them by providing as much detail as you can.
This prewritten response was triggered for you by fellow SAS Support Communities member @ballardw
.Use OS command ( LS or DIR ) to get these CSV pathname . And;
data have;
input fname $80.;
infile dummy filevar=fname end=last truncover dsd ;
do while(not last);
input x1 x2 x3 x4 .....;
output;
end;
cards;
C:temp\00001\x.csv
C:temp\00002\x.csv
..............
;
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.