One word of caution â since EST is 5 hours behind GMT, when you subtract 5
hours from GMT, that may put you in the previous day. So if you have date
information in addition to time, you may need to adjust the date as well.
For converting between time zones what I always do is: (1) create a
datetime variable of my existing data, (2) add or subtract hours as needed
for the new timezone, and (3) split out the new date and time into separate
variables. Like this:
*** GENERATE TEST DATA WITH 24 HOURS FOR ONE DAY ***;
data times;
do hour = 0 to 23;
gmt=hms(hour,5,0);
output;
end;
format gmt time5. ;
run;
title 'THIS EXAMPLE WILL PRODUCE NEGATIVE TIMES';
data example1;
set times;
est=gmt-(5*60*60);
format est time5. ;
run;
proc print data=example1;
run;
title 'THIS EXAMPLE WILL ADJUST TO THE PREVIOUS DAY AS NEEDED';
data example2;
set times;
*** IF YOU DO NOT HAVE THE GMT DATE IN YOUR DATASET, TEMPORARILY
USE TODAYS DATE ***;
gmt_date=today();
*** COMBINE GMT DATE AND TIME INTO A DATETIME VARIABLE ***;
gmt_datetime=dhms(gmt_date,0,0,gmt);
*** CONVERT DATETIME VARIABLE FROM GMT TO EST ***;
est_datetime=gmt_datetime - 5*60*60;
*** FOR EST - SPLIT OUT THE DATE AND TIME ***;
est=timepart(est_datetime);
est_date=datepart(est_datetime);
*** DROP UNNEEDED VARIABLES ***;
drop gmt_datetime est_datetime;
format gmt est time5. gmt_date est_date mmddyy10.;
run;
proc print data=example2;
run;
Here is a good website with tables to convert between GMT and timezones in
North America for both standard time and daylight savings time:
http://atm.geo.nsf.gov/ieis/time.html
Hope this helps,
Renee