Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- The extended penalty problem...

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 11-20-2013 05:49 PM
(1193 views)

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!

1 ACCEPTED SOLUTION

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?

5 REPLIES 5

- 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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- 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;`

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

What is Bayesian Analysis?

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.