Hi, this is probably an easy question, am looking to add a cumulative # of days a student made a mistake, and this resets to 0 when the student stop making mistakes. I have created a simple table to further illustrate my needs.
Date | Mistake_Flg | Days_Mistake_Streak |
1-Jan | 0 | 0 |
2-Jan | 0 | 0 |
3-Jan | 1 | 1 |
4-Jan | 1 | 2 |
5-Jan | 1 | 3 |
6-Jan | 0 | 0 |
7-Jan | 0 | 0 |
8-Jan | 1 | 1 |
9-Jan | 1 | 2 |
10-Jan | 0 | 0 |
Where "Days_mistake_streak" is what I'm trying to derive.
Thanks!
You could use something like:
data want;
set have;
retain Days_Mistake_Streak;
Days_Mistake_Streak=ifn(Mistake_Flg eq 0,0,Days_Mistake_Streak+1);
run;
You could use something like:
data want;
set have;
retain Days_Mistake_Streak;
Days_Mistake_Streak=ifn(Mistake_Flg eq 0,0,Days_Mistake_Streak+1);
run;
worked like a charm, thanks so much Arthur!
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 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.