2011-09-09 34 views
1

我在SPSS中導入的列中有時間戳。例如,7/6/2011 2:21在名爲'Observation'的列中如何從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).