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;
quickbluefish_0-1739206720291.png
CFC_SAS_Communities_400x225.jpg
It's your turn to help shape SAS Innovate 2027. Share your expertise and inspire the SAS community.
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.