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!
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.