Hello all,
I'm pulling in several text files (up to 100) stored on our SAS server that has a date on the file name that I need to incorporate into the imported file itself.
For example: From the infile statement below I need to extract the 20230221 portion of the file name and insert it as a variable into the file I'm creating. There is no rhyme or reason for the date sequence, just the date it's run on.
If I knew how to extract that date I could put it into a do-loop and run it that way. But the question is: how do I extract that file the file name for 100 text files?
Thanks!
INFILE '/sasdata/US/Sales/Weekly_Sales_20230221.txt'
LRECL=32767
FIRSTOBS=2
ENCODING="LATIN1"
DLM='09'x
MISSOVER
DSD ;
How are you creating the INFILE statement in the first place? Is it maintained manually or is it generated automatically? In any case just add the FILENAME option on your INFILE statement and the variable you specify will contain the name of the file you are reading:
INFILE '/sasdata/US/Sales/Weekly_Sales_20230221.txt'
FILENAME = MyFile
LRECL=32767
FIRSTOBS=2
ENCODING="LATIN1"
DLM='09'x
MISSOVER
DSD ;
Two things to keep in mind:
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.