2011-09-09 20 views
1

私はSPSSでインポートした列にタイムスタンプを持っています。例:7/6/2011 2:21「観測」の列SPSSのDateTimeから特定の値を減算する方法

これは文字列形式です。現在、これらのデータのタイムゾーン補正も行っています。したがって、-60はこの日から60分を減算することを意味します。

これをSPSS構文でどのように行うのですか?

答えて

2

SPSSにはネイティブの日付形式がありますが、残念ながら投稿した例は含まれていません。私はmm/dd/yyyyhh:mmの部分を別々にし、それらを代表的な時間形式に変換して時間計算を行うために文字列フィールドの先頭を解析します。例えば

data list fixed/observation (A25). 
begin data 
7/6/2011 2:21 
10/11/2011 15:42 
07/06/2011 02:21 
3/15/2011 0:21 
end data. 

*getting the data part, assuming the space will always delimit the two parts. 
compute #space = char.index(observation," "). 
string date (A10). 
compute date = char.substr(observation,1,#space-1). 
*getting the time part. 
string time (A5). 
compute time = char.substr(observation,#space+1,5). 
execute. 

*now converting them into date formats. 
alter type date (A10 = ADATE10). 
alter type time (A5 = TIME5). 
*you should check these carefully to make sure they were converted correctly. 
*now making one time variable. 
compute date_time = date + time. 
formats date_time (DATETIME17). 
execute. 

*now it is just as simple as subtracting the specified value. 
compute date_time_adj = DATESUM(date_time,-60,"minutes"). 
execute. 
formats date_time_adj (DATETIME17). 
関連する問題