Converting numerical variables into datetime

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

gratefulgradstudent
Posts: 2
Joined: Tue Mar 03, 2015 1:28 am

Converting numerical variables into datetime

Postby gratefulgradstudent » Tue Mar 03, 2015 1:33 am

Hello,

I am trying to recode a variable. My original survey asked participants to enter a time of day they do an activity on the half hour, ranging from not applicable (coded as 1) to 12:00am on day 1 (coded as “2”) to 5:30am the following day (day 2; coded as “61”). I asked participants to enter acivity times for 7 consecutive days, with the last times going into 5:30am on day 8.

I am trying to recode these variables (1 to 61 for each day) to what I believe is called datetime syntax, so that for “day 1,” what SPSS currently coded as “2” will become 12:00am on Day 1 (or on an arbitrary day), and so that variable 58, for instance, would be coded as 4:00am on day 2.

I have struggled with how to recode these so that I can then manipulate the dates and times to calculate individual and group averages, activity durations, and the like. I am fine with picking arbitrary “dates” for days 1-8, but I am having trouble with the correct recoding syntax for datetime. Any help would be much appreciated!

-grateful grad student
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Converting numerical variables into datetime

Postby GerineL » Tue Mar 03, 2015 8:37 am

I am not entirely sure what it is you want to achieve. do I understand correctly that you have currently a variable which holds a number between 1 and 61, and you have a list of date/times coresponding to those numbers, and you want to recode them?
If not, please tell us what it is you want to achieve.
If so, can you indicate what you've tried and didn't work out?
gratefulgradstudent
Posts: 2
Joined: Tue Mar 03, 2015 1:28 am

Re: Converting numerical variables into datetime

Postby gratefulgradstudent » Thu Mar 05, 2015 10:50 pm

Yes, that's correct. I currently have a variable which holds a number between 1 and 61, and i have a list of date/times corresponding to them and want to recode.
We have tried to compute a new variable that would include a series of numbers corresponding to a date and time (e.g., 010000 should be midnight day 1). This did not work, the format didn’t “stick” - even though the variable type was set to date, this number sequence wasn’t interpreted by spss as a date/time. For example, I've tried recoding where old variable is srm.mo_1 and new variable is nsrm.mo_1 like this, where 1 is date and 003000 corresponds to 12:30 am, like this: "if srm.mo_1=3 nsrm.mo_1=1003000." This was not interpreted by spss as a date/time.

We also tried converting a string variable of a similar form to the one above into a date, using the “date and time wizard” and this did not provide the result we wanted.

Hope this helps. Thanks.

GerineL wrote:I am not entirely sure what it is you want to achieve. do I understand correctly that you have currently a variable which holds a number between 1 and 61, and you have a list of date/times coresponding to those numbers, and you want to recode them?
If not, please tell us what it is you want to achieve.
If so, can you indicate what you've tried and didn't work out?
GerineL
Moderator
Posts: 1477
Joined: Tue Jun 10, 2008 4:50 pm

Re: Converting numerical variables into datetime

Postby GerineL » Fri Mar 06, 2015 9:18 am

I also always have trouble with date/time variables.
A way around it could be to make a new spss file containing the nrs (1-61) and corresponding dates, and merge the date variable with the original file!

Who is online

Users browsing this forum: No registered users and 1 guest

cron