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
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.