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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.