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
data test;
days_of_month = (datetime() - intnx('dtmonth',datetime(),0,'b')) / 86400;
run;
data test;
days_of_month = (datetime() - intnx('dtmonth',datetime(),0,'b')) / 86400;
run;
thanks!
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;
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.
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.
Ready to level-up your skills? Choose your own adventure.