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

Thank you Matt!

PG
pr1
Calcite | Level 5 pr1
Calcite | Level 5

This code is giving me false positive. 

I have character data that has ID Numbers.  It is 9 character long string and has numbers as char data from 0 to 9.  I am trying to identify if 5 or more consecutive characters are the same.  If yes, then I will create a flag. 

I have this code below.  It works most of the time but also gives me false positive.  For example, it will pick up something like 121341111 – where the ‘1’ is within the string 5 or more times.

I want to identify only if a character is present consecutively 5 or more times.  121341111 should not be flagged 1 repeated consecutively only 4 times. 

Any idea?

data want(drop = i) ;

  set have ;

  length ssn_char ssn_rept_chars $9;

  ssn_char = ssn;

  do i=1 to 6 until (flag=1);

  if substr(ssn_char, i, 1) = substr(ssn_char, i+1, 1) = substr(ssn_char, i+2, 1) = substr(ssn_char, i+3, 1

      then flag=1;

if flag = 1 then ssn_rept_chars = ssn_char;

  end;

run;

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 16 replies
  • 9399 views
  • 13 likes
  • 9 in conversation