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

Any idea on how to create a variable that will give the number of days so far in the month...including hours?

 

For example, at 9pm tonight (March 25 ,2019), the variable dayssofar would be 24 days + 21hrs/24hrs = 24 + 0.875 = 24.875 days.

Therefore dayssofar would equal 24.875

 

thanks

 

1 ACCEPTED SOLUTION
3 REPLIES 3
PaigeMiller
Diamond | Level 26

You can use the datetime() function to get the current date and time, then subtract off the date/time of the beginning of the month to give you the answer in seconds. Then convert to days by dividing by 86400.

 

data want;
    current_datetime=datetime();
    seconds_from_month_start=current_datetime - intnx('dtmonth',current_datetime,0,'b');
    days_from_month_start = seconds_from_month_start / 86400;
run;

 

 

--
Paige Miller

SAS Innovate 2025: Register Today!

 

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 3 replies
  • 654 views
  • 0 likes
  • 3 in conversation