Thank you Matt!
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;
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.
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.