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
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.
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 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.