tstamp='2013-05-17T09:15:30–05:00'dt;SASタイムスタンプ定数を指定すると、現在のタイムゾーンとタイムゾーンオフセットを考慮して、タイムスタンプがローカル日時値に変換されます。
options timezone='asia/tokyo';
data _null_; o1=tzoneoff(); o2=tzoneoff('asia/tokyo'); put o1 time.; put o2 time.; run;SASログの出力は次のようになります。
-5:00:00 9:00:00
diff=abs(tzoneoff('america/new_york') - tzoneoff('asia/tokyo'));
options timezone='America/Chicago'; data _null_; tzid=tzoneid(); put 'Current time zone is ' tzid; tzn=tzonename('america/los_angeles'); put 'Time zone for Los Angeles: ' tzn; tznST=tzonename('america/los_angeles','10mar2013:01:00:00'dt); put 'Time zone for Los Angeles standard time: ' tznST; tznDT=tzonename('america/los_angeles','10mar2013:02:00:00'dt); put 'Time zone for Los Angeles daylight time: ' tznDT; tznSDT=tzonename('10mar2013:02:00:00'dt); put 'Time zone name for this SAS datetime: ' tznSDT; run;
Current time zone is AMERICA/CHICAGO Time zone for Los Angeles:PST Time zone for Los Angeles standard time:PST Time zone for Los Angeles daylight time:PDT Time zone name for this SAS datetime:CDT
options timezone='est'; data _null_; put ' The time zone is EST'; diff=abs(tzoneoff('america/new_york') - tzoneoff('europe/london')); put ' New York-London difference:' diff time.; diff=abs(tzoneoff('america/new_york') - tzoneoff('asia/tokyo')); put ' New York-Tokyo difference:' diff time.; put ' The SAS datetime is 2013-03-15T09:15:00+00:00 '; put ' '; put ' Change a SAS datetime to a UTC value '; put ' '; put ' The time zone offset +00:00 is for London '; put ' Subtract the 5 hours for the EST time zone offset'; stu1=tzones2u('2013-03-15T09:15:00+00:00'dt); put ' STU1 Using E8601DX:' stu1 e8601dx.; put ' '; put ' 2013-03-15 9:15 AM in Tokyo is 2013-03-14 7:15 PM in New York'; put ' Subtract the 5 hours for the EST time zone offset'; stu2=tzones2u('2013-03-15T09:15:00+00:00'dt, 'Asia/Tokyo'); put ' STU2 Using E8601DX:' stu2 e8601dx.; put ' '; put ' Change a UTC to a SAS datetime value. '; put ' '; put ' +00:00 is the time zone offset for London.'; put ' Subtract the 5 hours for the EST time zone offset'; uts1=tzoneu2s('2013-03-15T09:15:00+00:00'dt); put ' UTS1 Using DATETIME:' uts1 datetime.; put ' '; put ' 9:15:00+00:00 is 18:15:00 in Tokyo. '; put ' Subtract the 5 hours for the EST time zone offset'; uts2=tzoneu2s('2013-03-15T09:15:00+00:00'dt, 'Asia/Tokyo'); put ' UTS2 Using DATETIME:' uts2 datetime.; run;
The time zone is EST New York-London difference:5:00:00 New York-Tokyo difference:14:00:00 The SAS datetime is 2013-03-15T09:15:00+00:00 Change a SAS datetime to a UTC value The time zone offset +00:00 is for London Subtract the 5 hours for the EST time zone offset STU1 Using E8601DX:2013-03-15T04:15:00-05:00 2013-03-15 9:15 AM in Tokyo is 2013-03-14 7:15 PM in New York Subtract the 5 hours for the EST time zone offset STU2 Using E8601DX:2013-03-14T14:15:00-05:00 Change a UTC to a SAS datetime value.+00:00 is the time zone offset for London.Subtract the 5 hours for the EST time zone offset UTS1 Using DATETIME:14MAR13:23:15:00 9:15:00+00:00 is 18:15:00 in Tokyo.Subtract the 5 hours for the EST time zone offset UTS2 Using DATETIME:15MAR13:13:15:00
options timezone='Australia/Sydney'; data _null_; st='18:33:40't; sdt='2013-03-17T14:30:22+00:00'dt; put 'Time B8601TX:' st b8601tx.; put 'Time E8601TX:' st e8601tx.; put 'UTC B8601DX:' sdt b8601dx.; put 'UTC E8601DX:' sdt e8601dx.; put 'UTC B8601LX:' sdt b8601lx.; put 'UTC E8601LX:' sdt e8601lx.; run;
Time B8601TX: 043340+1000 Time E8601TX:04:33:40+10:00 UTC B8601DX: 20130318T123022+1100 UTC E8601DX:2013-03-18T12:30:22+11:00 UTC B8601LX: 20130318T013022+1100 UTC E8601LX:2013-03-18T01:30:22+11:00
options timezone='Indian/Maldives'; data _null_; st='18:33:40't; sdt='2013-03-17T14:30:22+00:00'dt; put 'Time NLDATMTZ:' st nldatmtz.; put 'SAS datetime NLDATMZ:' sdt nldatmz.; put 'SAS datetime NLDATMWZ:' sdt nldatmwz.; run;
Time NLDATMTZ:18:33:40 +0500 SAS datetime NLDATMZ:17Mar2013:19:30:22 +0500 SAS datetime NLDATMWZ:Sunday, March 17, 2013 07:30:22 PM +0500
/* Set the time zone */ options timezone='America/Los_Angeles'; data depart; /* Set the departure time */ depart='2013-05-17T09:15:00-08:00'dt; put 'Depart Los Angeles: ' depart nldatmwz.; /* Set the flight time */ ftime='13:00't; put 'Flight time=' ftime time.; utc=depart+ftime; put 'Arrive PST=' utc nldatmwz.; put 'Arrive UTC=' utc nldatmwz.; run; /* Set the time zone for Tokyo */ options timezone='Asia/Tokyo'; data arrive; set depart; put 'Arrive in Tokyo ' utc nldatmwz.; run;
39 /* Set the time zone */ 40 options timezone='America/Los_Angeles'; 41 data depart; 42 /* Set the departure time */ 43 depart='2013-05-17T09:15:00-08:00'dt; 44 put 'Depart Los Angeles:' depart nldatmwz.; 45 /* Set the flight time */ 46 ftime='13:00't; 47 put 'Flight time=' ftime time.; 48 utc=depart+ftime; 49 put 'Arrive PST=' utc nldatmwz.; 50 put 'Arrive UTC=' utc nldatmwz.; 51 run; Depart Los Angeles:Friday, May 17, 2013 10:15:00 AM -0700 Flight time=13:00:00 Arrive PST=Friday, May 17, 2013 11:15:00 PM -0700 Arrive UTC=Friday, May 17, 2013 11:15:00 PM -0700 NOTE:The data set WORK.DEPART has 1 observations and 3 variables.NOTE:DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds 52 /* Set the time zone for Tokyo */ 53 options timezone='Asia/Tokyo'; 54 data arrive; 55 set depart; 56 put 'Arrive in Tokyo ' utc nldatmwz.; 57 run; Arrive in Tokyo Friday, May 17, 2013 11:15:00 PM +0900 NOTE:There were 1 observations read from the data set WORK.DEPART.NOTE:The data set WORK.ARRIVE has 1 observations and 3 variables.NOTE:DATA statement used (Total process time): real time 0.01 seconds cpu time 0.01 seconds