Hello!
I am trying to figure out how to dynamically have my program grab a file in from a subfolder, so that I do not have to manually go into the program and update it every time.
The directory structure is like this:
Main Folder
20200501
20200502
20200503
I need the program to look at the Modified Date of the folder and determine which one is the most recent. I can then have SAS read the file from that subfolder.
Does anyone have any suggestions?
Thanks!
First you can get list of all folders from that sub directory and then sort them ascending or descending by the folder name and pick the latest, based on last observation or first observation depending on how you sorted it, store it in a macro variable and use it. Hope this helps.
Filename filelist pipe "dir /b /s <path>";
Data file_list;
length folder_name $8.;
Infile filelist truncover;
Input filename $100.;
*separator is set based on os / for unix and linux \ for windows;
folder_name = input(scan(filename,-2,separator),best12.);
Put filename=;
Run;
proc sql;
select folder_name into: foldername from file_list
where folder_name = max(folder_name);
quit;
Data file_list_to_process;
set file_list;
if index(folder_name,"&foldername") > 0;
Put filename=;
Run;
First you can get list of all folders from that sub directory and then sort them ascending or descending by the folder name and pick the latest, based on last observation or first observation depending on how you sorted it, store it in a macro variable and use it. Hope this helps.
Filename filelist pipe "dir /b /s <path>";
Data file_list;
length folder_name $8.;
Infile filelist truncover;
Input filename $100.;
*separator is set based on os / for unix and linux \ for windows;
folder_name = input(scan(filename,-2,separator),best12.);
Put filename=;
Run;
proc sql;
select folder_name into: foldername from file_list
where folder_name = max(folder_name);
quit;
Data file_list_to_process;
set file_list;
if index(folder_name,"&foldername") > 0;
Put filename=;
Run;
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.