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!
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.