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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.