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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 16 replies
  • 11622 views
  • 13 likes
  • 9 in conversation