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

Hi All,

I have a problem that I have research many different ways.  I'm trying to import an excel spreadsheet that contains a date field that is customized as such  1/14/2018 10:43:00 AM which is the variable 'e' below. I imported the data using a libname, an import proc and also added options to the import with no success .  The problem is as follows  

 

Here's the code.

data fix;

set sr222;

x=e;

dt1 = dhms(x,0,0,0);

format dt1 datetime20.:

run:

 

It converts that variable okay but SAS is adding to the date.  For example:

incoming date = 1/5/2018 3:10:00 PM 

conversion date = 06JAN2078:15:10:00

 

can anybody please help

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

if i understand you correctly, your x , e are datetime values and not date values, you perhaps need to do

 

data fix;

set sr222;

x=e;

dt1 = dhms(datepart(x),0,0,0);

format dt1 datetime20.:

run:

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

if i understand you correctly, your x , e are datetime values and not date values, you perhaps need to do

 

data fix;

set sr222;

x=e;

dt1 = dhms(datepart(x),0,0,0);

format dt1 datetime20.:

run:

art297
Opal | Level 21

The difference between what you have coming in, and what you're getting, is simply the difference between SAS datetimes and Excel datetimes. One represents the number of seconds since Jan 1, 1900, while the other (SAS) represents the number of seconds since Jan 1, 1960.

 

To convert the datetimes you can use code like:

data fix;
  set sr222;
  dt1 = e-21916*86400;
  format dt1 datetime20.:
run:

Art, CEO, AnalystFinder.com

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

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