BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasnewbie5
Fluorite | Level 6

Screen Shot 2018-12-11 at 11.57.22 AM.png

 

Using the above screenshot of data, I am trying to determine the employees that are eligible for a 1% bonus. 

The certifications are only valid for seven years. Any certification tests passed over seven years ago from today’s date are expired. I need to eliminate those employees that have expired certifications in either Base or Advanced tests. Then output the remaining employees’ names, certification dates, and their bonuses to the output window using appropriate date and dollar formats. I can tell that only 2 employees are eligible for the bonus (Morris and Stewart), but I have no idea as to how write the code to output the desired results.

 

Please help if you can!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
data want;
    set work.bonus;
    /* Check for expired certifications */
    if not (intck('year',basedate,today(),'C')<7 and
        intck('year',advanceddate,today(),'C')<7) then delete;
    bonus=salary*0.01;
run;

The logic in my original IF statement was incorrect. The above code fixes it.

--
Paige Miller

View solution in original post

12 REPLIES 12
PaigeMiller
Diamond | Level 26

UNTESTED CODE

 

data want;
    set have;
    /* Check for expired certification */
    if not (intck('year',basedate,today(),'C')<7 or
        intck('year',advanceddate,today(),'C')<7) then delete;
    bonus=salary*0.01;
run;
    
--
Paige Miller
sasnewbie5
Fluorite | Level 6

Thank you PaigeMiller. After adding that to the code, it only deletes the base dates that are less than 7 years. It doesn't appear to do it for the advanced dates. Do you perhaps have any input as to why? Thanks!

PaigeMiller
Diamond | Level 26

If you could provide your data as a SAS data step, I (or someone) could actually provide code that has been tested.

https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat...

--
Paige Miller
sasnewbie5
Fluorite | Level 6

@ Paige,

 

I hope this is what you mean. Please see below.

 

data WORK.BONUS;
infile datalines dsd truncover;
input name:$8. salary:32. basedate:MMDDYY10. advanceddate:MMDDYY10. bonus:32.;
format basedate MMDDYY10. advanceddate MMDDYY10.;
datalines;
CAMPBELL 104600 12/01/2012 01/01/2008 1046
EDWARDS 72300 02/01/2013 06/01/2010 723
MORRIS 87200 02/04/2013 11/01/2012 872
ROGERS 70700 07/01/2012 10/01/2008 707
SANCHEZ 103300 09/01/2012 11/01/2009 1033
;;;;
PaigeMiller
Diamond | Level 26

Obviously, you didn't test this code, because it doesn't read the data properly. And honestly, I have other things more important to me than getting your data to read properly. You get the data to read properly, and then I'm sure I will have a solution to the original problem.

--
Paige Miller
sasnewbie5
Fluorite | Level 6

As a new user of SAS, I'm trying to learn the best I can. I did test all code and interpreted the results based on my limited knowledge.

 

With that being said, there's absolutely no need for you to be nasty nor rude about having "more important" things to do. Perhaps if you don't have the time to provide proper guidance/answers, you should not reply to any requests for real help. Thanks you, next.

PaigeMiller
Diamond | Level 26

My apologies. I did not intend to be rude, but it came out that way. I would still like to help you get the results you want.

--
Paige Miller
sasnewbie5
Fluorite | Level 6

I'm not sure what you meant by not getting the data to read properly - not sure how I'd know that it didn't. I've done all I could do with providing sample data for you and don't know how to move forward in getting you additional information you say you need. So, I suppose I will keep trying to adjust my code to obtain the desired results. Thanks.

ballardw
Super User

When I paste your code into the editor this is what I see:

data WORK.BONUS;.
infile datalines dsd truncover;.
input name:$8. salary:32. basedate:MMDDYY10. advanceddate:MMDDYY10. bonus:32.;.
format basedate MMDDYY10. advanceddate MMDDYY10.;.
datalines;.
CAMPBELL 104600 12/01/2012 01/01/2008 1046.
EDWARDS 72300 02/01/2013 06/01/2010 723.
MORRIS 87200 02/04/2013 11/01/2012 872.
ROGERS 70700 07/01/2012 10/01/2008 707.
SANCHEZ 103300 09/01/2012 11/01/2009 1033.
;;;;

I might guess that some of this code went through some program other than the SAS edtor that attached a bunch of periods at the ends of the lines. They cause ERRORS.

 

After removing the unwanted periods and removing the DSD option, which was forcing some pad reading based on the formats on the input I get this

data WORKBONUS;
   infile datalines  truncover;
   input name:$8. salary:32. basedate:MMDDYY10. advanceddate:MMDDYY10. 
         bonus:32.;
   format basedate MMDDYY10. advanceddate MMDDYY10.;
datalines;
CAMPBELL 104600 12/01/2012 01/01/2008 1046
EDWARDS 72300 02/01/2013 06/01/2010 723
MORRIS 87200 02/04/2013 11/01/2012 872
ROGERS 70700 07/01/2012 10/01/2008 707
SANCHEZ 103300 09/01/2012 11/01/2009 1033
;;;;

Which does run.

 

It does help on this forum to paste plain text, such as code or log entries into a code box opened with the {I} as the main message windows will reformat text and will allow odd characters that are not seen to sneak into the HTML.

sasnewbie5
Fluorite | Level 6

Thank you for the reply @ballardw. I can't say that I know what to do with the information you provided (I'm really new to SAS and don't know all of the processes and terminologies, etc.), but I do thank you for taking the time to provide additional information.

PaigeMiller
Diamond | Level 26
data want;
    set work.bonus;
    /* Check for expired certifications */
    if not (intck('year',basedate,today(),'C')<7 and
        intck('year',advanceddate,today(),'C')<7) then delete;
    bonus=salary*0.01;
run;

The logic in my original IF statement was incorrect. The above code fixes it.

--
Paige Miller
sasnewbie5
Fluorite | Level 6

Thank you very much.

Ready to join fellow brilliant minds for the SAS Hackathon?

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

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 12 replies
  • 1125 views
  • 2 likes
  • 3 in conversation