下面我通過一個簡單的例子利用xdate函數來提取一週的某一天,然後建設一個if語句來識別這些日期時間是否落入workhours
。
*Making example data.
data list free/xray_date (ADATE10) xray_time (TIME5).
begin data
7/6/2011 2:21
10/11/2011 15:42
07/06/2011 02:21
3/15/2011 0:21
end data.
*Here is example to find day of week name, 1 is Sunday and 7 is Saturday.
compute day_week = Xdate.Wkday(xray_date).
*to identify times of day in an if statement we need to make specific variables.
string begin_time end_time (A5).
compute begin_time = "08:00".
compute end_time = "17:00".
alter type begin_time end_time (TIME5).
*Then you can just make an if statement to identify whether a date-time meets your requirements.
compute workhours = 0.
if day_week >= 2 and day_week <= 6 and xray_time >= begin_time and xray_time <= end_time workhours = 1.
對於此特定示例,如果運行命令list all.
,則結果輸出將爲;
xray_date xray_time day_week begin_time end_time workhours
07/06/2011 2:21 4.00000 8:00 17:00 .00000
10/11/2011 15:42 3.00000 8:00 17:00 1.00000
07/06/2011 2:21 4.00000 8:00 17:00 .00000
03/15/2011 0:21 3.00000 8:00 17:00 .00000
你可以看到10/11/2011
紀錄被適當歸類,因爲它是一個星期二和工作時間。所有其他記錄不在上午8點到下午5點之間,因此初始化爲workhours
變量的零值。
我很困惑你的問題是什麼。目前的數據格式是什麼,以及您希望使用哪種格式? –
對不起,我可能沒有很好地解釋我自己。我手動輸入來自嬰兒X射線報告的原始數據。基本上我使用'date'作爲變量的類型輸入xray被執行的時間和日期作爲變量。我需要的是找出那天是星期天還是星期天,如果是在上午8點之前或下午5點之後。我可以很容易地手動完成這項工作,但我有大約6000個案例,所以它不太可行。我甚至不確定spss是否可以做這種事情,但我只是想我會檢查。 – user1481902
謝謝,這更清晰!我也許能寫了一個例子明天某個時候,但現在你要查找的[XDATE](http://publib.boulder.ibm.com/infocenter/spssstat/v20r0m0/index.jsp?topic=% 2Fcom.ibm.spss.statistics.help%2Fsyn_date_and_time_extraction_functions.htm)函數。他們幫助從每條記錄中提取特定的所需數據時間信息,然後可以通過if語句來確定標準。 –