Hi! I have a string like this one 'aaccbdaaaccc', and I need to find the character that occurs the most in consecutive order, and how many times it occurs. I thus need two variables as the output. I do not want to consider the caracter 'a'. The answer should be 'c' and '3'. Do anyone have a solution to this? Help is very much appreciated.
data _null_;
x='aaccbdaaaccc';
length str max_str $ 200;
pid=prxparse('/(\w)\1*/');
start=1;
stop=length(x);
max_len=0;
call prxnext(pid,start,stop,x,p,l);
do while(p>0);
str=substr(x,p,l);
len=length(str);
if str not =: 'a' and len gt max_len then do;
max_str=str;
max_len=len;
end;
call prxnext(pid,start,stop,x,p,l);
end;
putlog max_str= max_len= ;
run;
You've posted this in Enterprise Guide, are you using the query builder or familiar with SAS data steps?
data _null_;
x='aaccbdaaaccc';
length str max_str $ 200;
pid=prxparse('/(\w)\1*/');
start=1;
stop=length(x);
max_len=0;
call prxnext(pid,start,stop,x,p,l);
do while(p>0);
str=substr(x,p,l);
len=length(str);
if str not =: 'a' and len gt max_len then do;
max_str=str;
max_len=len;
end;
call prxnext(pid,start,stop,x,p,l);
end;
putlog max_str= max_len= ;
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.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.