BookmarkSubscribeRSS Feed
nds5134
Calcite | Level 5

I am trying to take a semi-automated code to become fully automated. Currently we have .txt files dropped daily in a folder with the naming convention FILE1_DS1_20181212_20181212.txt, sometimes this last part of the name is a range such as FILE2_DS1_20181210_20181212.txt.  Currently, every morning when I run the code I change the macro variables to match the correct dates which are needed (i.e %LET FILEDTE1=20181210, %LET FILEDTE2=20181212) so the files read in correctly. 

 

Is there a way for SAS to automatically pull those date values from the .txt file name? The date variables are later used in imports and outputs. 

 

FYI for more information we have 100+ text files that have this naming convention which are processed daily. I'm trying to account for data drops that cover the weekend, and other reasons,such as holidays, that may cause a date range. 

 

Thank You!

 

2 REPLIES 2
Reeza
Super User
I'll describe the process.
1. Write a small program that scans a folder and pulls all filenames
2. Filter filenames for ones relevant to you
3. Determine which files need to be read
4. Read
5. Repeat

All of these steps have been asked and answered on here, and some are actually in the SAS macro appendix.

Good Luck!
nds5134
Calcite | Level 5

Thank You! I will give this a try and post the code if it works.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1019 views
  • 0 likes
  • 2 in conversation