DATA Step, Macro, Functions and more

convert datetimes to another time zone

Regular Contributor
Posts: 204

convert datetimes to another time zone

I have a variable with the following three observations in datetime format.
These date times are in UTC (coordinated universal time). I would like to convert them to PST (pacific standard).
Does SAS have a tool for converting date time values to other time zones?
Super Contributor
Super Contributor
Posts: 3,176

Re: convert datetimes to another time zone

No specific "tool" - you need only use some data condition to test (revealing the time-zone), and then use a DATA step (or PROC SQL) programming technique to adjust (either increment or decrement) the SAS DATETIME variable value.

One example using a SAS assignment statement within a DATA step:

data _null_;
format UTC_DT Local_DT DATETIME21. ;
UTC_DT = datetime(); /* assign current SAS datetime var */
if () then TimeZoneOffset = -"5:00:00"t;
else if () then TimeZoneOffset = -"6:00:00"t;
else do;
* unknown condition code - abort maybe? ;
Local_DT = SUM(UTC_DT,TimeZoneOffset);
putlog _all_;

Scott Barry
SBBWorks, Inc.

Suggested Google advanced search argument, this topic / post:

date datetime variables
Valued Guide
Posts: 653

Re: convert datetimes to another time zone

Under Windows and Unix there is the TZ environment variable that might prove to be useful. Take a look at:
Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation