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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 2365 views
  • 0 likes
  • 3 in conversation