- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi, first let me apologize for not being more clear on the title as I am not sure how to discribe what I am looking for in just a few words. I am essentially trying to derive the Extended Penalty column in the table below:
Date | Mistakes_Flg | Number Of consecutive mistakes | Penalty | Extended_Penalty |
1/1/2013 | 0 | 0 | 0 | 0 |
1/2/2013 | 1 | 1 | 10 | 0 |
1/3/2013 | 1 | 2 | 10 | 0 |
1/4/2013 | 0 | 0 | 0 | 0 |
1/5/2013 | 1 | 1 | 10 | 0 |
1/6/2013 | 1 | 2 | 10 | 0 |
1/7/2013 | 1 | 3 | 10 | 0 |
1/8/2013 | 1 | 4 | 10 | 0 |
1/9/2013 | 0 | 0 | 0 | 10 |
1/10/2013 | 0 | 0 | 0 | 10 |
1/11/2013 | 0 | 0 | 0 | 10 |
1/12/2013 | 0 | 0 | 0 | 10 |
1/13/2013 | 0 | 0 | 0 | 0 |
where if the person makes mistakes for 3 or more consecutive days, he gets punished by paying an daily extended penalty of the previous penalty equal to the number of consecutive days he made a mistake. In my example, the first time he made a mistake for 2 consecutive days, no extended penalty has incurred since it's less than the 3 days criteria. However, he then made a mistake for 4 consecutive days, therefore he will have to pay the extended penalty for 4 more days after he stop making mistakes. Can someone help I tried everything and I can't get it work!
Thanks a bunch in advance!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What do you have working? I'm assuming you have an ID field somewhere as well?
If someone makes a mistake for 3 days then there's a 3 day penalty or is more than 3?
What happens if they make mistakes for 8 days, stop for 4 days and then starts again?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
What do you have working? I'm assuming you have an ID field somewhere as well?
If someone makes a mistake for 3 days then there's a 3 day penalty or is more than 3?
What happens if they make mistakes for 8 days, stop for 4 days and then starts again?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Or extending Reeza's question:
-Mistakes for 8 days, followed by no mistakes 4 days --> Extended penalty on the 4 no mistake days
-This is then followed by: Mistakes for 3 days after no mistakes for 4 days, followed by no mistakes for 4 days --> Extended penalty on the 3 mistake days. I'm clear to this point. Now what happens on the first no mistake day in this section--is it double extended penalty (1 day carried over from the 8 day period, plus the first from the more recent 3 day period), or just extend from the recent 3 day and have a single extended penalty?
This is a lot like coding for disease cases. If we say that no new case can begin until after n days have passed since the last day of signs or symptoms the logic is similar. It is just that in the epidemiology situation n is usually predefined, while here it is a matter of looking backward.
Steve Denham
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
you guys are so awesome! I was comtemplating the same issues while looking into the contracts (People who wrote those contracts never thought of those issues!) I will try to simply the problem first, if i still have some questions in regards to the coding aspect I will follow it up on this thread. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
To answer the 'simple' case, I think the easiest method to explain is simply to have one more column: "Number of remaining extended penalty days". Make it work exactly like your "Number of consecutive mistakes" column, but in reverse - count down from 4 to 3 to 2 to 1.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
The excellent explanation of your problem challenged me to write a 9-statement solution plus comments as follows. Hope you enjoy it ...
Data Mistakes;
/*-----------------------------------------------------------------*/
/* Generate simulation table with dates and some random Mistakes */
/*-----------------------------------------------------------------*/
Attrib Date Length = 4 Format = Date11.
Mistake Length = 2 Format = 1.;
Do Date = '01-jan-2013'd to '31-dec-2013'd;
Mistake = Round (RanUni (5), 1);
Output;
End;
Run;
/*1*/Data Mistakes;
/*-----------------------------------------------------------------*/
/* Re-generate table, including PENALTIES_TO_GO and PENALTY values */
/*-----------------------------------------------------------------*/
/*2*/ Attrib Date Length = 4 Format = Date9.
Mistake Length = 3 Format = 1.
Penalty Length = 3 Format = 1.
Penalties_to_go Length = 3 Format = 8.
/*3*/ Set Mistakes;
/*-----------------------------------------------------------------*/
/* PENALTY becomes 1 if current and last 3 dates all had MISTAKE=1 */
/*-----------------------------------------------------------------*/
/*4*/ Penalty = Mistake * Lag1 (Mistake)
* Lag2 (Mistake) * Lag3 (Mistake);
/*-----------------------------------------------------------------*/
/* Accumulate the number of PENALTIES_TO_GO */
/*-----------------------------------------------------------------*/
/*5*/ Penalties_to_go + Penalty;
/*-----------------------------------------------------------------*/
/* If current+last 3 days had MISTAKE=1, and 4 days ago MISTAKE=0, */
/* then increase the PENALTIES_TO_GO by an additional 3 penalties. */
/*-----------------------------------------------------------------*/
/*6*/ If Penalty > Lag4 (Mistake) >= 0 Then Penalties_to_go + 3;
/*-----------------------------------------------------------------*/
/* Assign a PENALTY if current date has MISTAKE=0 and there are */
/* still one or more PENALTIES_TO_GO. */
/*-----------------------------------------------------------------*/
/*7*/ Penalty = (Error = 0 and Penalties_to_go > 0);
/*-----------------------------------------------------------------*/
/* Decrease the number of PENALTIES_TO_GO only if PENALTY=1 */
/*-----------------------------------------------------------------*/
/*8*/ Penalties_to_go + -Penalty;
/*9*/ Run;
Proc Print Uniform;
Run;