BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
JT99
Obsidian | Level 7
Hello
I have a data with two dates, start_date and end_date. If any day in Apr2020 falls between those two dates, then I will create a new variable with value=‘Y’ else value=‘N’. I know it looks easy but I have no idea how to code this.
I’m thinking:
Data want: set have:
If AnyDayInApril2020 between start_date and end_date then value =‘Y’ else value=‘N’; run;
How do I consider the whole month of April into the code? It doesn’t have to be the entire month. As long as a day in Aprl, ex 12Apr2020 is between the two dates then it is valid.

Thanks!
1 ACCEPTED SOLUTION
4 REPLIES 4
Jagadishkatam
Amethyst | Level 16
could you please provide a sample data with expected output to help you
Thanks,
Jag
JT99
Obsidian | Level 7
Thank you so much for this solution! I feel bad I never thought of this. Thanks again!
Kurt_Bremser
Super User

It is always good to look at the inverse of a problem; in this case "which individual conditions for the dates would make it impossible for the range to contain a day of April 2020?"

This results in

if start_date gt '30apr2020'd

and

if end_dt lt '01apr2020'd

Since either would invalidate the whole condition, we use "or":

if start_date gt '30apr2020'd or end_dt lt '01apr2020'd

Then we apply some Boolean logic: to invert a compound condition (two conditions connected with AND or OR), you invert the individual parts and convert the logical operator to its opposite; that results in the solution you accepted.

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 9231 views
  • 1 like
  • 3 in conversation