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

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 389 views
  • 0 likes
  • 3 in conversation