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

One of my variables is made up of long strings.  Similar to the following:

 

CODE

01|02|03|04|07|0A|0B|0C

01|02|03|04|05|0A|0B

 

I have tried using % wildcard operator, which works in SQL, but I couldn't get it to work in SAS.  I also tried using * which I had seen used in another similar question.  I would like to use an IF THEN statement to do the following:

 

IF  CODE CONTAINS '03' THEN DO;

 

Unfortunately only arithmetic operators can be used with IF THEN statements.  I considered using the SUBSTR function, but I don't know the starting position of the codes, they can change for each observation.  Any advice or ideas on how I can solve this issue?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
if find(code,'03') then do;
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26
if find(code,'03') then do;
--
Paige Miller
AMSAS
SAS Super FREQ

The wildcards only work with WHERE statements 

 

Take a look at PRXMATCH Function, and the examples

Reeza
Super User

@Anthony_eng wrote:

One of my variables is made up of long strings.  Similar to the following:

 

CODE

01|02|03|04|07|0A|0B|0C

01|02|03|04|05|0A|0B

 

I have tried using % wildcard operator, which works in SQL, but I couldn't get it to work in SAS.  I also tried using * which I had seen used in another similar question.  I would like to use an IF THEN statement to do the following:

 

IF  CODE CONTAINS '03' THEN DO;

 

Unfortunately only arithmetic operators can be used with IF THEN statements.  I considered using the SUBSTR function, but I don't know the starting position of the codes, they can change for each observation.  Any advice or ideas on how I can solve this issue?


INDEXW/FINDW are functions you'll want. 

FIND will find 01 within 001. 

 

I think the statement in purple contradicts itself, not sure why you think "only arithmetic operators can be used with IF THEN statements". 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 941 views
  • 2 likes
  • 4 in conversation