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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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