BookmarkSubscribeRSS Feed
SteelersPitts
Obsidian | Level 7

Hi All,

 

I've a table with "run date" field. Can anyone let me know how I can create a date range field?

 

For example:

If Run date is 7/18/2018 then in the weekday range column I need to show the value "7/15/2018-7/21/2018" 

 

Thank you for all the help!!

4 REPLIES 4
tomrvincent
Rhodochrosite | Level 12
Use INTNX function to add/subtract days from the run date.
novinosrin
Tourmaline | Level 20
data w;
k='18jul2018'd;
range=catx('-',put(intnx('WEEK',k,0,'b'),mmddyy10.),put(intnx('week',k,0,'e'),mmddyy10.));
format k mmddyy10.;
run;
Reeza
Super User

You need CATX and the INTNX functions.

 

The last parameter in the INTNX function is the alignment parameter. That tells SAS to return the beginning of a week or end of a week for example. So setting the interval to 0, means find the first and last of the week with the b/e alignment options. 

 

@novinosrin code illustrates this. 

 


@SteelersPitts wrote:

Hi All,

 

I've a table with "run date" field. Can anyone let me know how I can create a date range field?

 

For example:

If Run date is 7/18/2018 then in the weekday range column I need to show the value "7/15/2018-7/21/2018" 

 

Thank you for all the help!!


 

Astounding
PROC Star

All of these answers are sniffing in the right direction.  But you'll need to clarify the problem a bit.  What should the result be for these run dates?

 

7/20/2018

7/21/2018

7/22/2018

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1095 views
  • 3 likes
  • 5 in conversation