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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 8053 views
  • 13 likes
  • 9 in conversation