Help using Base SAS procedures

The extended penalty problem...

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

The extended penalty problem...

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:

DateMistakes_FlgNumber Of consecutive mistakesPenaltyExtended_Penalty
1/1/20130000
1/2/201311100
1/3/201312100
1/4/20130000
1/5/201311100
1/6/201312100
1/7/201313100
1/8/201314100
1/9/201300010
1/10/201300010
1/11/201300010
1/12/201300010
1/13/20130000

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
Solution
‎11-20-2013 05:56 PM
Super User
Posts: 19,850

Re: The extended penalty problem...

Posted in reply to sweetgorgor

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?

View solution in original post


All Replies
Solution
‎11-20-2013 05:56 PM
Super User
Posts: 19,850

Re: The extended penalty problem...

Posted in reply to sweetgorgor

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?

Respected Advisor
Posts: 2,655

Re: The extended penalty problem...

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

Occasional Contributor
Posts: 8

Re: The extended penalty problem...

Posted in reply to SteveDenham

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!

Super Contributor
Posts: 253

Re: The extended penalty problem...

Posted in reply to sweetgorgor

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.

Occasional Contributor Aad
Occasional Contributor
Posts: 8

Re: The extended penalty problem...

Posted in reply to sweetgorgor

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;

🔒 This topic is solved and locked.

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

Discussion stats
  • 5 replies
  • 286 views
  • 7 likes
  • 5 in conversation