Hi, Im trying to use index function to search for the following string:
%put('ERROR
However I think the % with single quote (enslosed by double quote marks" is causing errors. Is there a way to search for the string without errors?
This is how I used the index function:
index(intext, "%put('ERROR")=0
Hi @kalbo,
Use the %NRSTR function to mask the %put keyword and place percent signs before the unmatched parenthesis and quotation mark as described in the documentation.
Example:
data _null_;
input intext $30.;
p=index(intext, "%nrstr(%put%(%'ERROR)");
put p=;
cards;
TEST%put('ERRORmore_text
;
EDIT: Alternatively, you can limit the %NRSTR function to the %put keyword and omit the additional percent signs:
p=index(intext, "%nrstr(%put)('ERROR");
Hi @kalbo,
Use the %NRSTR function to mask the %put keyword and place percent signs before the unmatched parenthesis and quotation mark as described in the documentation.
Example:
data _null_;
input intext $30.;
p=index(intext, "%nrstr(%put%(%'ERROR)");
put p=;
cards;
TEST%put('ERRORmore_text
;
EDIT: Alternatively, you can limit the %NRSTR function to the %put keyword and omit the additional percent signs:
p=index(intext, "%nrstr(%put)('ERROR");
data a;
string_to_find='%put('||"'ERROR";
intext='%put('||"'ERROR";
if index(intext, string_to_find)=0 then put 'ABC';
else put 'XYZ';
run;
Mask single quotes:
index(intext, '%put(''ERROR')
by doubling it inside single quotes.
Bart
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.