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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.