- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello @zdeb15,
Your question requires more details before experts can help. Can you revise your question to include more information?
Review this checklist:
- Specify a meaningful subject line for your topic. Avoid generic subjects like "need help," "SAS query," or "urgent."
- When appropriate, provide sample data in text or DATA step format. See this article for one method you can use.
- If you're encountering an error in SAS, include the SAS log or a screenshot of the error condition. Use the Photos button to include the image in your message.
- It also helps to include an example (table or picture) of the result that you're trying to achieve.
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
.- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
..............
;