BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
TMiles
Quartz | Level 8

I'm trying to automate a program that reads in EXCEL files.  Currently I have to browse to the Windows directory to see what files have been added, then I copy/paste into my program.

 

I want to scan the Windows Folder and find the files with yesterdays date dynamically to create my filename statement.

 

Is that possible?

 

Thanks,

Tammy

1 ACCEPTED SOLUTION

Accepted Solutions
SuryaKiran
Meteorite | Level 14

Hi,

 

You can run x-commands to read all the files in a folder. Does your excel files have datestamp on files names? If yes and you don't have access to run x-commands then the following code can read the files in a specific folder.

FILENAME _folder_ "%bquote(C:\Program Files\test)";
data filenames(keep=memname);
  handle=dopen( '_folder_' );
  if handle > 0 then do;
    count=dnum(handle);
    do i=1 to count;
      memname=dread(handle,i);
      output filenames;
    end;
  end;
  rc=dclose(handle);
run;
filename _folder_ clear;

 

Thanks,
Suryakiran

View solution in original post

3 REPLIES 3
LinusH
Tourmaline | Level 20

Yes, there are multiple ways to do it.

You could either use SAS external file functions to find out directory contents, files and their creation dates (FINFO).

Or, have an OS script prepare that information for you, import it to SAS, and use macro coding to generate FILEAME based on that.

Data never sleeps
SuryaKiran
Meteorite | Level 14

Hi,

 

You can run x-commands to read all the files in a folder. Does your excel files have datestamp on files names? If yes and you don't have access to run x-commands then the following code can read the files in a specific folder.

FILENAME _folder_ "%bquote(C:\Program Files\test)";
data filenames(keep=memname);
  handle=dopen( '_folder_' );
  if handle > 0 then do;
    count=dnum(handle);
    do i=1 to count;
      memname=dread(handle,i);
      output filenames;
    end;
  end;
  rc=dclose(handle);
run;
filename _folder_ clear;

 

Thanks,
Suryakiran
TMiles
Quartz | Level 8

This works great -what is the command to find the file create date so I only get the files  I need each day?  Or if you can point me to documentation I would be most grateful.

 

Thank you

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 3 replies
  • 1961 views
  • 0 likes
  • 3 in conversation