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

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:

elginelgfirstDay(Meets Criteria?)--Column not in dataset
DEC2009DEC20142013-01-01YES
FEB2007MAR20102009-05-01YES
OCT2016OCT20172015-01-01NO: Eligible after "FirstDay"
JAN1999MAR20092009-09-01NO: Eligibility ends before "FirstDay"
NOV2015JAN20182016-01-01NO" Not eligible for a full 12 months prior to "FirstDay"
SEP2013DEC20172016-02-01YES

 

Want:

elginelgfirstDay
DEC2009DEC20142013-01-01
FEB2007MAR20102009-05-01
SEP2013DEC20172016-02-01
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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;

 

--
Paige Miller
ssulli11
Calcite | Level 5

Thank you so much!  This was a much simpler solution that what I was trying to make work. 

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!
What is ANOVA?

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.

Discussion stats
  • 2 replies
  • 641 views
  • 0 likes
  • 2 in conversation