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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1666 views
  • 1 like
  • 2 in conversation