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


hi guys,

Can anyone please tell me what i am doing wrong  here

data test;

date='02oct2014'd;

format date datetime18.;

run;

the date in the output is 1/1/1960 5:33:18 AM

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You are trying to write a date (number of days) using a datetime format. So it is interpreting the number of days as the number of seconds.

View solution in original post

6 REPLIES 6
Tom
Super User Tom
Super User

You are trying to write a date (number of days) using a datetime format. So it is interpreting the number of days as the number of seconds.

stat_sas
Ammonite | Level 13

In order to get it in datetime format, try something like this

data test;

date='02oct2014'd;

new_date=date*86400;

format date date9. new_date datetime18.;

run;

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

thank you both

so i actually used new_date=dhms(date,00,00,00) and  then applied the format datetime.

Tom
Super User Tom
Super User

You could also just write a datetime literal instead of a date literal.

datetime='02oct2014:00:00'dt;

Tal
Pyrite | Level 9 Tal
Pyrite | Level 9

I know but the thing is this date variable is actually a macro var from another SAS code which resolves to 02oct2014 so I had to use the "&date"d in the dhms function

SASKiwi
PROC Star

Using Tom's method you could specify "&date.:00:00:00"dt to resolve your SAS date as a datetime.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 1347 views
  • 5 likes
  • 4 in conversation