Hi everyone, I'm working with informations about customers along 136 months.
What I'm working on is an specific information about those customers that express a situation that can from a month to another. With this data in hands I'm building a report to specify the duration (in months) of each situation.
For example, concatenating all these situation for an hypothetic customer we would have:
customer_historic='00000666668888888888880000000000000000777777777777777777770000000006666666'
At first I could say that on the first five months the situation was 0 and lasted for 5 months.
And since the 6th month the situation began to be 6, and it lasted for 5 months as well.
And then, from the 11th month it started to be 8, and it lasted for 8 months
.....
But, using formulas, I just can identify the beginning of this sequence, which could be done using:
FIRST_NUMB_SEQUENCE = INDEX(customer_historic,'0');
Which the result would be FIRST_NUMB_SEQUENCE = '1'.
Does anyone know a way to identify when, along the sequence, the digit starts to be different from 6 ? Is possible to do that using INDEX function ?
Or an alternative way.
Thanks in advance.
Here one way of doing this. Code based on example from docu here.
data have;
id=1;
customer_historic='00000666668888888888880000000000000000777777777777777777770000000006666666';
output;
id=2;
call missing(customer_historic);
output;
stop;
run;
data want(drop=_:);
set have;
length value $1;
_exprid = prxparse('/(\d)\1*/');
_start = 1;
_stop = lengthn(customer_historic);
if _stop=0 then output;
else
do;
/* Use PRXNEXT to find the first instance of the pattern, */
/* then use DO WHILE to find all further instances. */
/* PRXNEXT changes the _start parameter so that searching */
/* begins again after the last match. */
call prxnext(_exprid, _start, _stop, customer_historic, first_numb_sequence , _len);
do while (first_numb_sequence > 0);
value = substrn(customer_historic, first_numb_sequence , 1);
last_numb_sequence=first_numb_sequence+_len-1;
output;
call prxnext(_exprid, _start, _stop, customer_historic, first_numb_sequence , _len);
end;
end;
run;
proc print;
run;
Many suggestions might be made, but why not show us what the resulting data set would look like? That will help narrow down the relevant answers. For instance, if a customer's history has, say 7 "regimes", do you want seven output records (and what would they look like)? If some other structure, what would it look like?
Here one way of doing this. Code based on example from docu here.
data have;
id=1;
customer_historic='00000666668888888888880000000000000000777777777777777777770000000006666666';
output;
id=2;
call missing(customer_historic);
output;
stop;
run;
data want(drop=_:);
set have;
length value $1;
_exprid = prxparse('/(\d)\1*/');
_start = 1;
_stop = lengthn(customer_historic);
if _stop=0 then output;
else
do;
/* Use PRXNEXT to find the first instance of the pattern, */
/* then use DO WHILE to find all further instances. */
/* PRXNEXT changes the _start parameter so that searching */
/* begins again after the last match. */
call prxnext(_exprid, _start, _stop, customer_historic, first_numb_sequence , _len);
do while (first_numb_sequence > 0);
value = substrn(customer_historic, first_numb_sequence , 1);
last_numb_sequence=first_numb_sequence+_len-1;
output;
call prxnext(_exprid, _start, _stop, customer_historic, first_numb_sequence , _len);
end;
end;
run;
proc print;
run;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.
Ready to level-up your skills? Choose your own adventure.