DATA Step, Macro, Functions and more

Create dummy if certain number is in variable

Accepted Solution Solved
Reply
Contributor
Posts: 28
Accepted Solution

Create dummy if certain number is in variable

I am trying to create a dummy variable that signals to me if a certain number sequence is found in a variable. So i have the "Variable" field, and am trying to create the "In Sequence" field (dummy can be yes/no or 1/1 either works for me.

 

EXAMPLE: Does variable include 830 ?

 

    Variable                       In Sequence?

LPAR0198308                        YES

TRAE8307028                        YES

MK109362791                        NO

P01823974830                       YES

WQTUAR2930                        NO

 

I am using SAS EG 7.1


Accepted Solutions
Solution
‎08-24-2017 02:33 PM
Super User
Posts: 6,543

Re: Create dummy if certain number is in variable

Posted in reply to Amber_Nicole94

The INDEX function works here.  One possibility:

 

in_sequence = (index(variable, '830') > 0);

View solution in original post


All Replies
Solution
‎08-24-2017 02:33 PM
Super User
Posts: 6,543

Re: Create dummy if certain number is in variable

Posted in reply to Amber_Nicole94

The INDEX function works here.  One possibility:

 

in_sequence = (index(variable, '830') > 0);

Contributor
Posts: 28

Re: Create dummy if certain number is in variable

Posted in reply to Astounding

That worked! Thanks!

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 100 views
  • 0 likes
  • 2 in conversation