Help using Base SAS procedures

Searching for special characters...

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Searching for special characters...

I've had a quick search for any previous questions along these lines, but couldn't find any. Apologies if this has been asked before.

I'm currently trying to search data for occurances of free text which includes the asterisk (*) symbol. I need to extract records where the asterisk is included, however I am concerned that in searching for something like "A*,X,Y,Z"...

e.g.

index ([column label], ".A*,X,Y,Z")

...the asterisk symbol is being considered as a wildcard, so this search would pick-up on entries like: "Az,X,Y,Z" and "A5,X,Y,Z", etc...

1. Are my concerns valid?

2. Is there any way around this?

Thanks in advance for any help.

Cheers

Nick


Accepted Solutions
Solution
‎01-30-2012 06:18 AM
Frequent Contributor
Frequent Contributor
Posts: 94

Searching for special characters...

Posted in reply to FlippantDonkey

I don't think this is a concern.  For example, the below outputs as I would expect:

data dsn;

format str $50.;

infile datalines dsd;

input str $;

i = index (str, ".A*,X,Y,Z");

datalines;

"zzz.A*,X,Y,Zzzz"

"zzz.Azzzzzzzzz,X,Y,Zzzz"

;

run;

Only the first entry is picked up by Index.  If the asterisk (or a percentage sign, etc.) were treated as a wildcard, then it would pick up both rows.

If you wanted to include wildcards you might consider using the REGEX functions like PRXMATCH() etc..

View solution in original post


All Replies
Solution
‎01-30-2012 06:18 AM
Frequent Contributor
Frequent Contributor
Posts: 94

Searching for special characters...

Posted in reply to FlippantDonkey

I don't think this is a concern.  For example, the below outputs as I would expect:

data dsn;

format str $50.;

infile datalines dsd;

input str $;

i = index (str, ".A*,X,Y,Z");

datalines;

"zzz.A*,X,Y,Zzzz"

"zzz.Azzzzzzzzz,X,Y,Zzzz"

;

run;

Only the first entry is picked up by Index.  If the asterisk (or a percentage sign, etc.) were treated as a wildcard, then it would pick up both rows.

If you wanted to include wildcards you might consider using the REGEX functions like PRXMATCH() etc..

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 129 views
  • 0 likes
  • 2 in conversation