BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hello, guys.
i am a beginner in SAS 🙂
I have a SAS-log file, and i want to find a word (ex: "STOP") there and the line number of it.
i try to make a simple code to find the word like this:

data temp;
length word $20;
infile "c:\temp\myFile.LOG" dlm=' ';
input word $ @@;
run;

data findWord;
set temp;
where upcase(word) like 'STOP' ;
run;

any idea to find the line number? or another code?
thank you.

regards,
capricornday
6 REPLIES 6
GertNissen
Barite | Level 11
data findWord;
set temp;
where upcase(word) like 'STOP' ;
line_number1 = _n_;
line_number2 +1;
run;
deleted_user
Not applicable
thanks to Geniz,

but this isn't exactly what i mean..
From log file is a text like this :

line ...
line 1999
line 2000 NOTE: The SAS System stopped processing this step because of errors.
line 2001 NOTE: SAS set option OBS=0 and will continue to check statements.
line 2002 This may cause NOTE: No observations in data set.
line 2003 WARNING: The data set WORK.DATA may be incomplete.
line 2004 When this step was stopped there were 0
line 2005 observations and 0 variables.
line 2006
line ....


so.. i have 2 lines contain word 'STOP'

line word
----------- ------------
2000 stop
2004 stop
.... ....

thanks
regards

capricornday
Cynthia_sas
SAS Super FREQ
Hi:
Several folks have written papers about post-processing the SAS log file. This is just one of them. If you look at the programs in this paper, you may get some ideas of how to proceed:
http://analytics.ncsu.edu/sesug/2004/SY05-Foley.pdf

cynthia
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Beware that you may not always find a consistent line-numbering "experience" with SAS, unfortunately. However, with very basic SAS program executions, you should find the SAS "line number" followed by the respective code for that line.

My recommendation is to read the log file, a line at a time, parsing it for a line number, followed by some remaining text (to be either a "note", "error", or maybe SAS code.


Scott Barry
SBBWorks, Inc.

SAS 9.2 Language DOC - Reading Raw Data
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001112330.htm
deleted_user
Not applicable
thanks for the link! and i will check the "Reading Raw Data" again.. 😄

regards

capricornday
Peter_C
Rhodochrosite | Level 12
This kind of thing is a straightforward requirement, so it should be easy.
Infile option line= helps.[pre]data stops( keep= row line ) ;
do until( end_of_data ) ;
infile 'your log file' line= rowNum scanover ;
input @'STOP' @ ;
row= rowNum ; * variables named by statement options cannot be kept;
length line $256 ;
line= _infile_ ;
input ; * release current line ;
end ;
stop ;
run ;[/pre]What introduces a difficulty is that the line= information seems to be reset at each data step iteration, so you have to avoid that by coding your own iteration (like that demo above).

Good Luck

PeterC

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 1039 views
  • 0 likes
  • 5 in conversation