You can use a wildcard in the filename.
You could just try to read ALL of the files that match the pattern. You can use the FILENAME= option on the INFILE statement to find the name of the file you are reading.
data logs;
length fname filename $200;
infile "&path./log_%sysfunc(today(), ddmmyyN8.)*.log" filename=fname ;
input;
filename=fname;
lineno+1;
if filename ne lag(filename) then lineno=1;
line=_infile_;
run;
filename log "&path.\log_%sysfunc(today(), ddmmyyN8.) *.log";
@Crt wrote:
Hi everyone!
I am trying to read the latest file from a folder.
Requirements:
1) The folder stores files as:
log_26112021 123456.log
2) The file format is the name_date numbers. There is a space between the date and the numbers.
What I have done so far is:
filename log "&path.\log_%sysfunc(today(), ddmmyyN8.).log';
What I want to do is to read the rest of the file name, whatever it is including the space and the numbers. Any suggestions?
Thank you in advance!
You can use a wildcard in the filename.
You could just try to read ALL of the files that match the pattern. You can use the FILENAME= option on the INFILE statement to find the name of the file you are reading.
data logs;
length fname filename $200;
infile "&path./log_%sysfunc(today(), ddmmyyN8.)*.log" filename=fname ;
input;
filename=fname;
lineno+1;
if filename ne lag(filename) then lineno=1;
line=_infile_;
run;
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.