Help using Base SAS procedures

Add a cumulative count that resets when value = 0

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Add a cumulative count that resets when value = 0

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.

DateMistake_FlgDays_Mistake_Streak
1-Jan00
2-Jan00
3-Jan11
4-Jan12
5-Jan13
6-Jan00
7-Jan00
8-Jan11
9-Jan12
10-Jan00

Where "Days_mistake_streak" is what I'm trying to derive.

Thanks!


Accepted Solutions
Solution
‎10-23-2013 11:39 AM
PROC Star
Posts: 7,356

Re: Add a cumulative count that resets when value = 0

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;

View solution in original post


All Replies
Solution
‎10-23-2013 11:39 AM
PROC Star
Posts: 7,356

Re: Add a cumulative count that resets when value = 0

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;

Occasional Contributor
Posts: 8

Re: Add a cumulative count that resets when value = 0

worked like a charm, thanks so much Arthur!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 176 views
  • 1 like
  • 2 in conversation