SPSSのデータタイムから特定の分割を差し引く方法
-
28-10-2019 - |
質問
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).
所属していません StackOverflow