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

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!

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
smantha
Lapis Lazuli | Level 10

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;

 

View solution in original post

2 REPLIES 2
smantha
Lapis Lazuli | Level 10

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;

 

biglerc
Obsidian | Level 7
Thank you so much for the great suggestion!

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
  • 2 replies
  • 1996 views
  • 1 like
  • 2 in conversation