Hi Guys,
I want to write a code that picks only one record for each employee based on review date that falls between effective date and expiry date..
Any help much appreciated
i need only below record to pick from below data..
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20029828 | 20012838 | 930049 | CLI | 013423 | 02Mar2015 | 11Apr2018 | MAY2018 | MAR2015 | APR2018 |
please check below sample data..
Review_Date | Name | Reviewmonth | RO | EMPL_I | EMPL_M | EMPL_STUS_C | POSN_I | PARN_POSN_I | JOB_C | JOB_FUNC_C | DEPT_I | EFFT_D | EXPY_D | appmonth | Joinmthyy | Endmthyy |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20012841 | 20012872 | 900802 | CSL | 005513 | 31Jul2000 | 09Jun2003 | MAY2018 | JUL2000 | JUN2003 |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20012841 | 20012872 | 902312 | LND | 005513 | 10Jun2003 | 23Nov2003 | MAY2018 | JUN2003 | NOV2003 |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20012841 | 20012872 | 901459 | IB | 005513 | 24Nov2003 | 07Jan2004 | MAY2018 | NOV2003 | JAN2004 |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20029525 | 900661 | OTH | 012113 | 08Jan2004 | 09Jan2005 | MAY2018 | JAN2004 | JAN2005 | |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20012841 | 20012872 | 901459 | IB | 005513 | 10Jan2005 | 07Mar2005 | MAY2018 | JAN2005 | MAR2005 |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20012841 | 20026356 | 901459 | IB | 005513 | 08Mar2005 | 08Mar2005 | MAY2018 | MAR2005 | MAR2005 |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20012841 | 20012872 | 901459 | IB | 005513 | 09Mar2005 | 04Aug2005 | MAY2018 | MAR2005 | AUG2005 |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20029828 | 20012847 | 904956 | CSL | 005513 | 05Aug2005 | 06Nov2005 | MAY2018 | AUG2005 | NOV2005 |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20029828 | 20012847 | 903755 | CSL | 005513 | 07Nov2005 | 29Dec2005 | MAY2018 | NOV2005 | DEC2005 |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20029828 | 20012838 | 903755 | CSL | 005513 | 30Dec2005 | 18Jul2006 | MAY2018 | DEC2005 | JUL2006 |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20029828 | 20012847 | 903755 | CSL | 013423 | 19Jul2006 | 31Oct2006 | MAY2018 | JUL2006 | OCT2006 |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20029828 | 20012838 | 903755 | CSL | 013423 | 01Nov2006 | 29Apr2007 | MAY2018 | NOV2006 | APR2007 |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20029828 | 20064500 | 903755 | CSL | 013423 | 30Apr2007 | 01May2007 | MAY2018 | APR2007 | MAY2007 |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20029828 | 20012838 | 903755 | CSL | 013423 | 02May2007 | 14Sep2008 | MAY2018 | MAY2007 | SEP2008 |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20036820 | 900661 | OTH | 012255 | 15Sep2008 | 07May2009 | MAY2018 | SEP2008 | MAY2009 | |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | LWP | 20036820 | 900661 | OTH | 012255 | 08May2009 | 13Sep2009 | MAY2018 | MAY2009 | SEP2009 | |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20036821 | 900659 | OTH | 012255 | 14Sep2009 | 31Dec2009 | MAY2018 | SEP2009 | DEC2009 | |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20029828 | 20012838 | 903755 | CSL | 013423 | 01Jan2010 | 22Jun2011 | MAY2018 | JAN2010 | JUN2011 |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20029828 | 20012838 | 930049 | CLI | 013423 | 23Jun2011 | 16Oct2011 | MAY2018 | JUN2011 | OCT2011 |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20029828 | 20012838 | 930049 | CLI | 013423 | 17Oct2011 | 03Mar2013 | MAY2018 | OCT2011 | MAR2013 |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | LWP | 20036820 | 930527 | OTH | 012255 | 04Mar2013 | 01Mar2015 | MAY2018 | MAR2013 | MAR2015 | |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20029828 | 20012838 | 930049 | CLI | 013423 | 02Mar2015 | 11Apr2018 | MAY2018 | MAR2015 | APR2018 |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20029828 | 20012838 | 930051 | CLI | 013423 | 12Apr2018 | 31Dec2099 | MAY2018 | APR2018 | DEC2099 |
.
This should just be a straightforward where condition. Does something like the below not work?
where EFFT_D <= Review_Date <= EXPY_D;
No its not working..it did tried this method...and also below one..
WHERE max(EFFT_D) <= Review_date <= max(EXPY_D);
can you post a sample of your expected output for an/your input sample? ?This will help thr community to offer you precise solutions
Are your "dates" SAS date values? Comparisons seldom work when the values are character variables.
Run Proc contents to see what type and formats are associated with your data variables. If proc contents shows them as Char then that would be a major reason.
@BaalaRaaji wrote:
No its not working..it did tried this method...and also below one..
WHERE max(EFFT_D) <= Review_date <= max(EXPY_D);
"Its not working" is awful vague.
Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.
No output? Post any log in a code box.
Unexpected output? Provide input data in the form of data step code pasted into a code box, the actual results and the expected results. Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
Post test data in the form of a datastep, if you don't know how follow this post:
Only a few rows are needed (i.e. keep it simple and to the point). Then from that show what you want out at the end.
@JChambo's suggestion should work. Your code:
WHERE max(EFFT_D) <= Review_date <= max(EXPY_D);
You don't even show if this is SQL or datastep? How are we to know what "did not work"?
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.