BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Mick_bill
Fluorite | Level 6

I have a data set and I am trying to count how often this repeats consecutively across a particular volume of variables.

 

I have shown an example of what I have in the below dataset which has 13 variables, but i am looking at seeing how many Consecutive "Y"'s happen within a particular section. E.g. The example is from Var1-10 but this may change to look at between Var2-8 depending on requirements etc.

 

data have;
input (var1-var13)($);
cards;
Y Y N N Y Y Y N Y Y Y N N
Y Y Y Y Y Y Y Y Y Y N N N
Y N N N N Y N N Y Y Y N N
;
run;

 

Below you can see this count conservative Y's and output the largest volume the between var 1-10 giving the largest consecutive outcome between them in the final column. Is this possible to do?

 

data Want;
input (var1-var13)($) Total_Consecutive_Y_10vars;
cards;
Y Y N N Y Y Y N Y Y Y N N 3
Y Y Y Y Y Y Y Y Y Y N N N 10
Y N N N N Y N N N Y Y N N 1
;
run;

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
data have;
input (var1-var13)($);
cards;
Y Y N N Y Y Y N Y Y Y N N
Y Y Y Y Y Y Y Y Y Y N N N
Y N N N N Y N N Y Y Y N N
;
run;

data want;
 set have;
length temp $ 2000;
temp=cats(of var1-var10);

pid=prxparse('/Y+/o');
s=1;e=length(temp);want=0;
call prxnext(pid,s,e,temp,p,l);
do while(p>0);
 want=max(want,l);
 call prxnext(pid,s,e,temp,p,l);
end;

drop temp pid s e p l ;
run;

View solution in original post

1 REPLY 1
Ksharp
Super User
data have;
input (var1-var13)($);
cards;
Y Y N N Y Y Y N Y Y Y N N
Y Y Y Y Y Y Y Y Y Y N N N
Y N N N N Y N N Y Y Y N N
;
run;

data want;
 set have;
length temp $ 2000;
temp=cats(of var1-var10);

pid=prxparse('/Y+/o');
s=1;e=length(temp);want=0;
call prxnext(pid,s,e,temp,p,l);
do while(p>0);
 want=max(want,l);
 call prxnext(pid,s,e,temp,p,l);
end;

drop temp pid s e p l ;
run;

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 273 views
  • 0 likes
  • 2 in conversation