DATA Step, Macro, Functions and more

Where statement?

Accepted Solution Solved
Reply
Super Contributor
Posts: 398
Accepted Solution

Where statement?

Hello:

 

I would like to extract the text contain 'NOS' or 'MISC' from column A, D, G and H.   'NOS' and 'MISC' could be either capital or low case.  In additional, they could be only part of text.   For example, 'Defect-Nos' contains 'NOS'.   'MISCELLANEOUS' or 'MISC.' contain 'MISC'.   I would like to find all of the possibility.   In other words, the result should includes 'Defect-Nos',  'MISCELLANEOUS' and 'MISC.' from all of the four columns.   Could someone let me know how to approach it?  Thanks.


Accepted Solutions
Solution
‎12-08-2017 09:47 AM
Super User
Posts: 10,570

Re: Where statement?

To find a string within an other string, use the index() or find() functions.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code

View solution in original post


All Replies
Super User
Posts: 24,003

Re: Where statement?

Insert the words you're looking for into a temporary array and loop through your list. Look at the third parameters of the INDEX and FIND functions so they ignore case. 

Solution
‎12-08-2017 09:47 AM
Super User
Posts: 10,570

Re: Where statement?

To find a string within an other string, use the index() or find() functions.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 13,939

Re: Where statement?


ybz12003 wrote:

Hello:

 

I would like to extract the text contain 'NOS' or 'MISC' from column A, D, G and H.   'NOS' and 'MISC' could be either capital or low case.  In additional, they could be only part of text.   For example, 'Defect-Nos' contains 'NOS'.   'MISCELLANEOUS' or 'MISC.' contain 'MISC'.   I would like to find all of the possibility.   In other words, the result should includes 'Defect-Nos',  'MISCELLANEOUS' and 'MISC.' from all of the four columns.   Could someone let me know how to approach it?  Thanks.


You might want to consider the difference in the statement if change the highlighted all to any.

'All' would usually be used when you require the condition to be true for each and every column of interest. Which in much computer syntax means comparisons joined with "and". Any would be at least one of the is true so a computer syntax "or" would appear between comparisons.

 

Since you have multiple columns to search you might consider providing some example input and show the desired result.

The result is important as you could well have 4 "text containing". Should the result be in a single variable? four variables? If multiple variables is order important?

☑ This topic is solved.

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

Discussion stats
  • 3 replies
  • 156 views
  • 3 likes
  • 4 in conversation