SAS 9.2
I have a date field appointment_date and it shows '10Jan2014'. It is a date field and not text field.
And then I run this SAS code:
data NCA_OAOS3x;
set NCA_OAOS3 (where=(oaos_case_no='S140106-5'));
appt_date_timex=dhms(appointment_date,12,0,0);
format appt_date_timex datetime.;
run;
It returns 11JAN14:02:00:00
And if I run this SAS code:
data NCA_OAOS3x;
set NCA_OAOS3 (where=(oaos_case_no='S140106-5'));
appt_date_timex=dhms(appointment_date,0,0,0);
format appt_date_timex datetime.;
run;
It returns 10JAN14:14:00:00
Can anyone explain why the hour component is not returning as expected? There seems to be hour component in the date field. Date field is actually '10Jan14:14:00:00'
Provide a numeric, not date formatted value of your variable.
You might get this behavior if there are some decimals floating around.
If this:
appt_date_timex=dhms(floor(appointment_date),12,0,0);
fixes the problem that was the likely cause.
Provide a numeric, not date formatted value of your variable.
You might get this behavior if there are some decimals floating around.
If this:
appt_date_timex=dhms(floor(appointment_date),12,0,0);
fixes the problem that was the likely cause.
ballardw,
Thanks, it worked using floor. But why would there be a decimal in a date statement? Anyway it worked.
I would go back in your processes. Somebody may have converted hours to fraction of a day for another purpose. OR used a year to days conversion multiplying by 356.25 somewhere.
I imported the data from an excel file. And in excel I can see 10-Jan-2014 in formatted. The underlying in excel could be having decimal.
Lesson learnt: It is always safe to floor the date field then. Among a dataset of 10,000 rows, only a few of them had decimal and I was not aware of it unless my user feedback to me.
I thought the whole point of a date field is not to have any time component.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.