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
BCNAV
Quartz | Level 8

thanks!

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-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1055 views
  • 0 likes
  • 3 in conversation