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
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;
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.
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;
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
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!
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.
Ready to level-up your skills? Choose your own adventure.