我在 SPSS 中导入的列中有时间戳。例如,7/6/2011 2:21
在名为“观察”的列中
这是字符串格式。现在我也对这些数据进行了时区校正。因此,-60 表示从该日期减去 60 分钟。
我将如何在 SPSS 语法中执行此操作?
我在 SPSS 中导入的列中有时间戳。例如,7/6/2011 2:21
在名为“观察”的列中
这是字符串格式。现在我也对这些数据进行了时区校正。因此,-60 表示从该日期减去 60 分钟。
我将如何在 SPSS 语法中执行此操作?
SPSS 中有本地日期格式,但不幸的是,它似乎没有涵盖您发布的示例。我会解析字符串字段的开头以获取mm/dd/yyyy
和hh: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).