BookmarkSubscribeRSS Feed
tediest
Calcite | Level 5

Can SAS convert time from EST to GMT accounting for daylight saving? Or do I have to incorporate daylight saving days manually?

Thanks a lot in advance!

7 REPLIES 7
AncaTilea
Pyrite | Level 9

Here is a helpful link:

http://listserv.uga.edu/cgi-bin/wa?A2=ind0711a&L=sas-l&P=8219

data _null_;

  gmt = '20:05:09't;

  est = gmt - (4*60*60);

  pst = gmt - (7*60*60);

  format _all_ time.;

  put _all_;

run;

and here is another discussion:

tediest
Calcite | Level 5

Thanks. I saw this link earlier too. But it seems to work for daylight saving time only, in other cases we need to have est = gmt - (5*60*60) . I was wondering whether SAS can automatically identify days with DST.

AncaTilea
Pyrite | Level 9

from quickly scanning the internet, it seems that there is no automatic way to calculate it.

😐

data_null__
Jade | Level 19

This seems close but you will need "date time".

data _null_;
  
do local='03feb2012:01:03:03'dt, '04jul2012:01:03:03'dt, datetime();
      s = dhms(nwkdom(2,1, 3,year(datepart(local))),2,0,0);
      e = dhms(nwkdom(1,1,11,year(datepart(local))),2,0,0);
      adj = s le local le e;
      offset =
5 + adj;
      gmt = local + dhms(0,offset,0,0);
      put (_all_) (=);
      end;
  
format gmt local s e datetime20.;
  
run;
I forgot to mention this
Also if you are collecting time approaching 2am on "fall back day" what do you write down at 2am, the clock has been reset to 1am.   Instead of collecting in local time and converting to GMT you need to do it the other way round. Don't you?
FriedEgg
SAS Employee

DN gave a great response...  Daylight savings time is not some difficult unknown.  It occurs on the between then 2nd Sunday of March and the 1st Sunday of November, at 2:00am...

Another way to check could be to use the TimeZone class

proc groovy classpath=cp;

submit parseonly;

  class DST {

   static boolean isDst(String tmz) {

    return TimeZone.getTimeZone(tmz).inDaylightTime(new Date())

   }

  }

endsubmit;

run;

data test;

declare javaobj j('DST');

j.callStaticBooleanMethod('isDst',"EST",is_dst);

put is_dst=;

run;

is_dst=0;

est = gmt - ((5-(1*is_dst))*60*60);

art297
Opal | Level 21

Here is a file that contains timezone by zipcode, including whether dst is used in each zipcode.  And, since its timezones are already shown as difference from GMT, you only need to code whether to add the hour or not based on the date.  PS: its free!:

Free Zip Code Latitude and Longitude Database

kathy13
Calcite | Level 5

I don;t know

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!

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
  • 8418 views
  • 1 like
  • 6 in conversation