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