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

Hi,

I have a column which contains different codes separated by a space:

 

Column A

A20B3 B35XX Z70A2 A22VV

C30B3 B35XX Z70A2 C34VV

C30B3 B35XX Z70A2 A24VV

 

I now like to keep the rows where this column include codes beginning with A2

 

If I use "where column A contains A2" the two first rows will be kept which is uncorrect since no code in row 2 start with A2.

 

If I use "where column A in:A2" it will keep the first one, but the third row also have a code beggining with A2 which I want to keep.

 

Thanks for any help to solve this!

Thomas

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

No, you would really have to repeat the search:

 

where (index(' ' || columnA, ' A2') > 0) or (index(' ' || columnA, ' C2') > 0);

 

The more you add, the closer to get to having to learn parsing functions instead.

View solution in original post

5 REPLIES 5
Astounding
PROC Star

The trick to solving this easily and quickly (not searching every word in the string, avoiding parsing functions) is to append a blank at the beginning:

 

where index(' ' || columnA, ' A2') > 0;

bollibompa
Quartz | Level 8

Thanks!

Could I modify this index-argument if I want in the same search select several codes for example, codes that starts with A2 and C2?

/Thomas

Astounding
PROC Star

No, you would really have to repeat the search:

 

where (index(' ' || columnA, ' A2') > 0) or (index(' ' || columnA, ' C2') > 0);

 

The more you add, the closer to get to having to learn parsing functions instead.

bollibompa
Quartz | Level 8

Thanks for your replies!

PGStats
Opal | Level 21

where column =: "A2";

PG

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
  • 5 replies
  • 1957 views
  • 1 like
  • 3 in conversation