Hi I have a data set with text from a log file.
I have a variable called TEXT:
TEXT
put 'ERROR' blah blah blah
put "ERROR:" blah blah blah
var='ERROR' blah blah blah
var="ERROR" blah blah blah
I need to indentify cases where there is put followed by ERROR (in quotes) and cases where there is an = sign followed by ERROR (in quotes).
I was thinking of using index but thought PRXMATCH might be better due to the quote marks.
data want;
set have;
if find(text,"put 'ERROR'")>0 or find(text,'put "ERROR"')>0
or find(text,'="ERROR"')>0 or find(text,"='ERROR'")>0 then ...
;
run;
I didn't finish the "then ..." part of the code, whatever goes there is up to you.
You could try this with PRXMATCH (slight edit to deal with the optional colon):
data test;
infile cards dsd truncover firstobs=1 dlm=',';
length logstuff $100;
input logstuff;
cards;
put 'ERROR' blah blah blah
put "ERROR-" blah blah blah
put "ERROR:" blah blah blah
var='ERROR' blah blah blah
var="error" blah blah blah
something else
put ERROR
var=error
putERROR
;
run;
proc print data=test; run;
data want;
set test;
ismatch=0;
if prxmatch("m/^(put\s+|var=)\'error:?\'\s*/i",tranwrd(logstuff,'"',"'")) then ismatch=1;
run;
proc print data=want; run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.