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

Hi, experts,

I am a new learner of SAS. Now I have a large dataset with just 0 and 1(please see the attachment). For each ID, I want to find the times of stopout. Here, for instance, one stopout is like this, 101, 1001, 10001, and so on. For the first ID, 001010011, there are two stopouts. Thank you so much for your great help in advance!

 

Johnathan

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
johnthan
Fluorite | Level 6
Hi Astounding, Thank you for your response to my question. However, when I run the codes, the results of n_stopouts for each ID is zero!

View solution in original post

3 REPLIES 3
Astounding
PROC Star

Here's an approach:

 

data want;

set have;

array y {10};

n_stopouts = 0;

do i=1 to 10;

   if y{i} = 1 then do;stage=1;

      if stage=2 then n_stopouts + 1;

      stage=1;

   end;

   else if y{i} =0 and stage=1 then stage=2;

end;

drop stage;

run;

 

It's untested, but looks like it should work.

   

johnthan
Fluorite | Level 6
Hi Astounding, Thank you for your response to my question. However, when I run the codes, the results of n_stopouts for each ID is zero!
johnthan
Fluorite | Level 6
Hi Astounding, when I delete statement stage = 1 after the statement if y{i} = 1 then do, your codes works. Here, I would like to give you big "thank you" to you. Good night!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1375 views
  • 1 like
  • 2 in conversation