Your SAS programs, embedded in web apps and elsewhere

find a word in a raw data file

Reply
N/A
Posts: 0

find a word in a raw data file

Hello, guys.
i am a beginner in SAS Smiley Happy
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
SAS Employee
Posts: 160

Re: find a word in a raw data file

data findWord;
set temp;
where upcase(word) like 'STOP' ;
line_number1 = _n_;
line_number2 +1;
run;
N/A
Posts: 0

Re: find a word in a raw data file

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
SAS Super FREQ
Posts: 8,743

Re: find a word in a raw data file

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
Super Contributor
Super Contributor
Posts: 3,174

Re: find a word in a raw data file

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
N/A
Posts: 0

Re: find a word in a raw data file

thanks for the link! and i will check the "Reading Raw Data" again.. Smiley Very Happy

regards

capricornday
Valued Guide
Posts: 2,175

Re: find a word in a raw data file

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
Ask a Question
Discussion stats
  • 6 replies
  • 292 views
  • 0 likes
  • 5 in conversation