BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
kalbo
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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");

 

View solution in original post

3 REPLIES 3
FreelanceReinh
Jade | Level 19

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");

 

PaigeMiller
Diamond | Level 26
data a;
string_to_find='%put('||"'ERROR";
intext='%put('||"'ERROR";
if index(intext, string_to_find)=0 then put 'ABC';
else put 'XYZ';
run;
--
Paige Miller
yabwon
Amethyst | Level 16

Mask single quotes:

index(intext, '%put(''ERROR')

by doubling it inside single quotes. 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



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
  • 3 replies
  • 1013 views
  • 8 likes
  • 4 in conversation