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

 

Hi ,I want to convert Date_time character variable(IST) to EST (date and time format) .please help me.

 

original_date time_ist Date_time
28/12/2016 3:06:36 28DEC2016/3:06:36
11/11/2016 19:56:35 11NOV2016/19:56:35
11/11/2016 19:55:58 11NOV2016/19:55:58
11/11/2016 19:53:25 11NOV2016/19:53:25
11/11/2016 19:55:26 11NOV2016/19:55:26
11/11/2016 19:51:53 11NOV2016/19:51:53
11/11/2016 19:52:25 11NOV2016/19:52:25
16/11/2016 14:00:56 16NOV2016/14:00:56
16/11/2016 13:25:02 16NOV2016/13:25:02
16/11/2016 15:23:54 16NOV2016/15:23:54
16/11/2016 14:00:18 16NOV2016/14:00:18
16/11/2016 13:08:55 16NOV2016/13:08:55
16/11/2016 16:21:36 16NOV2016/16:21:36

 

Thanks,

Siva

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Well, IST is UTC+5:30, while ET (or EST) is UTC-5, so we have to subtract 10:30 from IST time to get the correct timestamp for ET:

data want;
input date_time :$20.;
dt_time = input(date_time,datetime20.);
format dt_time e8601dt20.;
dt_time = dt_time - '10:30:00't;
cards;
28DEC2016/3:06:36
11NOV2016/19:56:35
11NOV2016/19:55:58
11NOV2016/19:53:25
11NOV2016/19:55:26
11NOV2016/19:51:53
11NOV2016/19:52:25
16NOV2016/14:00:56
16NOV2016/13:25:02
16NOV2016/15:23:54
16NOV2016/14:00:18
16NOV2016/13:08:55
16NOV2016/16:21:36
;
run;

You now have a datetime value for Eastern Time, and can use datepart() and timepart() to extract the ET date and time values from that.

View solution in original post

7 REPLIES 7
Kurt_Bremser
Super User

Do

data want;
set have;
original_date = datepart(input(date_time,datetime20.));
time_ist = timepart(input(date_time,datetime20.));
format
  original_date ddmmyy10.
  time_ist time8.
;
run;
sivastat08
Pyrite | Level 9

Thanks sir.

sivastat08
Pyrite | Level 9
Hi KurtBremser, I want both variable (original_date) and (time_ist) should be concatenated in new column (Date_time) and also convert into EST format
Kurt_Bremser
Super User

Consulting wikipedia, the only date/time-related uses of the acronym EST are Eastern Standard Time and European Summer Time. Do you want to factor in a timezone?

 

Otherwise describe how the final variable should be formatted. When dealing with such values, it's usually best to keep the value as a true SAS datetime value (seconds from 1960-01-01T00:00:00) and use an appropriate format (you can even create a custom one yourself).

sivastat08
Pyrite | Level 9
original_datetime_ist
28/12/20163:06:36

 

Here original date is 28/12/2016 and ist time is 3:06:36 which is Indian Standard Time (IST), I want to convert it to 27/12/2016 and 17:06:36 Estern Standard Time (EST (USA/Canada)).

 

Kurt_Bremser
Super User

Well, IST is UTC+5:30, while ET (or EST) is UTC-5, so we have to subtract 10:30 from IST time to get the correct timestamp for ET:

data want;
input date_time :$20.;
dt_time = input(date_time,datetime20.);
format dt_time e8601dt20.;
dt_time = dt_time - '10:30:00't;
cards;
28DEC2016/3:06:36
11NOV2016/19:56:35
11NOV2016/19:55:58
11NOV2016/19:53:25
11NOV2016/19:55:26
11NOV2016/19:51:53
11NOV2016/19:52:25
16NOV2016/14:00:56
16NOV2016/13:25:02
16NOV2016/15:23:54
16NOV2016/14:00:18
16NOV2016/13:08:55
16NOV2016/16:21:36
;
run;

You now have a datetime value for Eastern Time, and can use datepart() and timepart() to extract the ET date and time values from that.

sivastat08
Pyrite | Level 9
Thank you very much for your time

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!

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
  • 7 replies
  • 4633 views
  • 1 like
  • 2 in conversation