Good afternoon!
I am trying to keep only data observations where an observation is "eligible" for all 12 months prior to their "firstDay". As always, I so appreciate the help of the community! Thank you!
Have:
elg | inelg | firstDay | (Meets Criteria?)--Column not in dataset |
DEC2009 | DEC2014 | 2013-01-01 | YES |
FEB2007 | MAR2010 | 2009-05-01 | YES |
OCT2016 | OCT2017 | 2015-01-01 | NO: Eligible after "FirstDay" |
JAN1999 | MAR2009 | 2009-09-01 | NO: Eligibility ends before "FirstDay" |
NOV2015 | JAN2018 | 2016-01-01 | NO" Not eligible for a full 12 months prior to "FirstDay" |
SEP2013 | DEC2017 | 2016-02-01 | YES |
Want:
elg | inelg | firstDay |
DEC2009 | DEC2014 | 2013-01-01 |
FEB2007 | MAR2010 | 2009-05-01 |
SEP2013 | DEC2017 | 2016-02-01 |
Here's the logic ... compute 12 months before first day, then see if inelg is less than first day and 12 months before first day is after elg. This assumes your variables are actual SAS dates. (If they are not actual SAS dates, then you have to convert them to actual SAS dates and work on those)
data want;
set have;
twelve_months_before=intnx('month',firstday,-12,'b');
if inelg>firstday and elg<=twelve_months_before then output;
run;
Here's the logic ... compute 12 months before first day, then see if inelg is less than first day and 12 months before first day is after elg. This assumes your variables are actual SAS dates. (If they are not actual SAS dates, then you have to convert them to actual SAS dates and work on those)
data want;
set have;
twelve_months_before=intnx('month',firstday,-12,'b');
if inelg>firstday and elg<=twelve_months_before then output;
run;
Thank you so much! This was a much simpler solution that what I was trying to make work.
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!ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.