BookmarkSubscribeRSS Feed
zdeb15
Calcite | Level 5

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

 

 

 

2 REPLIES 2
Community_Guide
SAS Moderator

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.
    use_buttons.png
  • 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.

 

edit_post.png

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

.
Ksharp
Super User

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

..............

;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 427 views
  • 0 likes
  • 3 in conversation