BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
hellind
Quartz | Level 8

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'

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

4 REPLIES 4
ballardw
Super User

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.

hellind
Quartz | Level 8

ballardw,

Thanks, it worked using floor. But why would there be a decimal in a date statement? Anyway it worked.

ballardw
Super User

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.

hellind
Quartz | Level 8

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

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
  • 4 replies
  • 792 views
  • 0 likes
  • 2 in conversation