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;

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
  • 4 replies
  • 1119 views
  • 1 like
  • 3 in conversation