BookmarkSubscribeRSS Feed
thanhnguyenhtl
Calcite | Level 5

Hi everyone,

I am new to SAS and world time converter. I have a file with UTC/GMT timezone that needs to convert to local time. The problem is that sometime 

If datetime is between 1 AM the last Sunday of March and 1 AM the last Sunday of October it is "summertime" in central Europe --> the date difference between local time and greenwich benchmark is -1 (not quite)

 And about Australia sometimes we need to date -1 , for American sometimes we need to creat date +1 .

Could you guys please advise the code that I can capture the real local time in these circumstances?

Thank you so much and have a nice day 

sas.JPG

 

5 REPLIES 5
Reeza
Super User

See this page, specifically:

Write ISO 8601 Time and Datetime Values Based on the Time Zone

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/nlsref/n0px72paaaqx06n1ozps024j78cl.htm

 

I'm not sure if those account for the issues you've noted but it's somewhere to start. 

 

 

thanhnguyenhtl
Calcite | Level 5
Hi Reeza,

Thank you so much for that, I'll try to figure it out.
Patrick
Opal | Level 21

@thanhnguyenhtl You basically need to convert your datetimes to UTC and then you can use a format to show the datetimes in your local time-zone.

Should you struggle with getting this to work: If you provide sample data via a SAS data step then I'm sure someone will show you the way.

 

For your case it's really important that we get the "correct" data so suggest you use The DATA to DATA Step Macro to provide the sample data - or alternatively attach a .sas7bdat file here.

thanhnguyenhtl
Calcite | Level 5

Hi Patrick,

 

Thank you for your reply. I want to convert GMT time to the local time of each country, but not sure about the summer time of some special zone. Sorry that I cannot create sas file because I am using sas studio on web :D. And here is the idea of my code: 

data &out; set &out;
if gmt_offset >=0 then
localTime=time_g_+hms(gmt_offset,0,0);
else
localTime=time_g_-hms(abs(gmt_offset),0,0);
if localTime ge "24:00:00"t then do date_g_= date_g_+1; localTime=localTime-"24:00:00"t; end;
format localTime time.; run;

 

Thank you so much,

VT

 

Tom
Super User Tom
Super User

If all you have is the offset from GMT then just use that. Note that the offset would need to reflect the value that is appropriate for the time of year (to reflect changes to daylight savings time).

It should not matter if the value is positive, zero or negative. Just multiple by it by the number of seconds in an hour. 

Note your TIME_G_ and LOCALTIME variables will need to be DATETIME variables (not just time of day variables) otherwise you will have headaches when the offset causes the time to cross the midnight.

localTime=time_g_ + gmt_offset * '01:00:00't ;

 

If you have the actual symbolic name for the timezone then use that. 

https://documentation.sas.com/doc/en/pgmsascdc/v_010/nlsref/n0px72paaaqx06n1ozps024j78cl.htm#p128wft...

 

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/nlsref/n1tj735aocxmw7n1kfoz1qpdvb9l.htm 

That might allow you to have it automatically adjust for daylight savings time.

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 4400 views
  • 0 likes
  • 4 in conversation