Hi Guys,
I have attached belwo sample data with two secnarios..i need help in wiritng a sas code to pick the latest record by comparing the Review date that falls between EFFT_D(Joing date) and EXPY_D(end date).
Any help is much appreciated.
n first scenario i should pick the belowrecord
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20029828 | 20012838 | 930051 | CLI | 013423 | 27Oct2016 | 31Dec2099 | MAY2018 | OCT2016 | DEC2099
|
in second scenario the below lrecord
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20029828 | 20012838 | 930049 | CLI | 013423 | 02Mar2015 | 11Apr2018 | MAY2018 | MAR2015 | APR2018 |
complete data below...
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 | 26Oct2016 | MAY2018 | MAR2015 | OCT2016 |
10Apr2018 | XXXYYY | APR2018 | XXX,YYY | 00183256 | XXX,YYY | ACT | 20029828 | 20012838 | 930051 | CLI | 013423 | 27Oct2016 | 31Dec2099 | MAY2018 | OCT2016 | DEC2099 |
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 |
Next time, trim your data set down to just the essential fields.
data first_set;
input
Review_Date:date9.
Name:$6.
Reviewmonth:MONYY7.
RO:$8.
EMPL_I:$8.
EMPL_M:$8.
EMPL_STUS_C:$4.
POSN_I:$9.
PARN_POSN_I:$9.
JOB_C:$9.
JOB_FUNC_C:$7.
DEPT_I:$7.
EFFT_D:date9.
EXPY_D:date9.
appmonth:MONYY7.
Joinmthyy:MONYY7.
Endmthyy:MONYY7.
;
format review_date yymmdd10. efft_d yymmdd10. expy_d yymmdd10.;
datalines;
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 26Oct2016 MAY2018 MAR2015 OCT2016
10Apr2018 XXXYYY APR2018 XXX,YYY 00183256 XXX,YYY ACT 20029828 20012838 930051 CLI 013423 27Oct2016 31Dec2099 MAY2018 OCT2016 DEC2099
;
run;
* we want the record with a review date between efft_d date and expy_d date;
proc sql;
select *
from first_set
where review_date between efft_d and expy_d;
quit;
That gives:
The SAS System 09:52 Thursday, May 3, 2018 1
Review_ EMPL_ PARN_POSN_
Date Name Reviewmonth RO EMPL_I EMPL_M STUS_C POSN_I I
JOB_FUNC_
JOB_C C DEPT_I EFFT_D EXPY_D appmonth Joinmthyy Endmthyy
2018-04-10 XXXYYY 21275 XXX,YYY 00183256 XXX,YYY ACT 20029828 20012838
930051 CLI 013423 2016-10-27 2099-12-31 21305 20728 51104
Yuck that is hard to read.
Try that.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.