BookmarkSubscribeRSS Feed
kalbo
Obsidian | Level 7

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.

2 REPLIES 2
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller
quickbluefish
Barite | Level 11

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

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 487 views
  • 0 likes
  • 3 in conversation