BookmarkSubscribeRSS Feed
JanA
Calcite | Level 5

Hi.

is it any easy way to look for specifik words in text files?

ex:

in a cataloge i have 100 files and i want to find all files that contain the word: "ERROR:" and print the file name.

BR

Jan

3 REPLIES 3
Tom
Super User Tom
Super User

If you are talking about operating system files then you can use grep for something like that.

> grep -l 'ERROR:' *.log

statistician13
Quartz | Level 8

The following SAS code, which will only work on the Windows OS, will search in the &let dir directory for all text files for the words specified in the &let SearchString= statement.  The names of the resulting files are stored in the variable filename in dataset work.Filenames:

%let dir=C:\users\mark\desktop\;

%let SearchString=data;

filename pipedir pipe   "FINDSTR /M /D:&dir ""&SearchString"" *.txt" lrecl=32767;

   data filenames;

     infile pipedir truncover;

     input filename $char1000.;

     if _n_ eq 1 then delete;

   run;

Patrick
Opal | Level 21

As it sounds you want to analyse SAS logs below 2 links might be of interest for you:

34301 - Parse SAS® Logs to Extract Performance and Timing Information

Base SAS(R) 9.3 Procedures Guide, Second Edition

The first link is pure SAS code. It's not scanning the log files for Warnings or Errors but the techniques used there can also be applied for these keywords.

Be aware that Error messages can span over more than one line so what Tom suggests would need some amendment in order to capture all lines and not only the first one with ERROR: in it.

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
  • 3 replies
  • 923 views
  • 0 likes
  • 4 in conversation