Hi i'm new to this site so forgive me if i didn't search for this question thoroughly enough!
Basically i'm doing a research project where one of the variables is whether an xray was performed during normal work hours or not. Work hours include Monday-Friday, 8am-5pm.
I have input the date and time of each xray using separate variables -[date+time (dd.mm.yyyy hh:mm)] -[time (hh:mm)].
I was planning on inputing this information manually but i though that surely there is way to automate this and since i have next to zero experience with SPSS i thought i should ask you lovely people to help me out!
Thankyou in advance
Below I go through a quick example utilizing the xdate function to extract the day of week, and then construction an if statement to identify whether these date-times fall within 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.
For this particular example, if you run the command list all.
the resulting output will be;
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
You can see the record with 10/11/2011
was appropriately classified as it is a Tuesday and within working hours. All of the other records are not between 8 am and 5 pm, so are initialized to the zero value for the workhours
variable.