BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Crt
Fluorite | Level 6 Crt
Fluorite | Level 6
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!
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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;

View solution in original post

4 REPLIES 4
Reeza
Super User
  • Mismatched quotes
  • * is the wildcard character
  • I'm unsure of the behaviour of this code if it resolves to multiple files

 

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!

 

Crt
Fluorite | Level 6 Crt
Fluorite | Level 6
Thank you for your response.

I have tried the * character, but it seems not to work.
Reeza
Super User
What do you mean 'it seems not to work'.
What are you expecting to happen and what happens?
How are you using the filename and how does it not work?
Code and log helps.
Tom
Super User Tom
Super User

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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 1195 views
  • 1 like
  • 3 in conversation