Custom Format Time Variable

classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Custom Format Time Variable

Brock-15
Hi Everyone,

I have a dataset with a variable that is a time, expressed as minutes and
seconds.  Think of a sporting event.  In SPSS, I see all sorts of time
formats, but none seem to allow me to format my variable as mm:ss.  Can I
create a custom format my variable?

Many thanks,

Brock

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Custom Format Time Variable

ViAnn Beadle
How about the TIME format?

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Brock
Sent: Sunday, May 03, 2009 12:22 PM
To: [hidden email]
Subject: Custom Format Time Variable

Hi Everyone,

I have a dataset with a variable that is a time, expressed as minutes and
seconds.  Think of a sporting event.  In SPSS, I see all sorts of time
formats, but none seem to allow me to format my variable as mm:ss.  Can I
create a custom format my variable?

Many thanks,

Brock

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Custom Format Time Variable

Brock-15
In reply to this post by Brock-15
Thanks for your help.

1) I am reading a text file that has a time variable.

2) I read the field in as a string since SPSS wants to make the
minutes->hours and seconds->minutes.

3)I then 'extract' the minutes into a seperate, numeric field called 'mins'
and the seconds into a numeric field called 'secs'.

4) I run date/time wizard to get the following syntax (it includes the 0 for
me):
       COMPUTE  time=TIME.HMS(0, mins, secs).

5) I get the error telling me that I am using an invalid combination of data
types, yet I can't complete the date/time wizard without converting the mins
and secs variables to numeric.

Thanks,

brock


------------

OK, you have to provide more information like what your data look like,
where you are reading them from, and what you intend to do with the
resulting variable. And do that publicly so others can chime in.

-----Original Message-----
From: Tibert, Brock [mailto:[hidden email]]
Sent: Sunday, May 03, 2009 12:58 PM
To: 'ViAnn Beadle'
Subject: RE: Custom Format Time Variable

Thanks for taking the time to respond.  Maybe I am missing something, but
even on page 63 of the command syntax reference (V17), I do not see how I
can modify/create syntax to make my variable mm:ss. I am not a professional
syntax writer, but typically can work my way through it.

I tried using the Date/Time wizard but keep getting an error.  The syntax
that is returned is:

COMPUTE  time=TIME.HMS(0, mins, secs).

But I am getting an error telling me that there is an invalid combination of
data types, yet mins and seconds (my two variables) are numeric.

Thanks,

Brock

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Custom Format Time Variable

ViAnn Beadle
How do you extract the components of the string variable? What syntax is
used? All of the arguments to TIME.HMS must be numeric. Here's an example
which uses the substr function to pluck out the minutes and seconds and the
use TIME.HMS.

data list list /x (a9).
begin data
04:02.22
05:33.01
end data.
compute mins=number(substr(x,1,2),f2).
compute secs=number(substr(x,4),f5).
compute time=TIME.HMS(0,mins,secs).
format time (time12.2).
list time.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Brock
Sent: Sunday, May 03, 2009 1:09 PM
To: [hidden email]
Subject: Re: Custom Format Time Variable

Thanks for your help.

1) I am reading a text file that has a time variable.

2) I read the field in as a string since SPSS wants to make the
minutes->hours and seconds->minutes.

3)I then 'extract' the minutes into a seperate, numeric field called 'mins'
and the seconds into a numeric field called 'secs'.

4) I run date/time wizard to get the following syntax (it includes the 0 for
me):
       COMPUTE  time=TIME.HMS(0, mins, secs).

5) I get the error telling me that I am using an invalid combination of data
types, yet I can't complete the date/time wizard without converting the mins
and secs variables to numeric.

Thanks,

brock


------------

OK, you have to provide more information like what your data look like,
where you are reading them from, and what you intend to do with the
resulting variable. And do that publicly so others can chime in.

-----Original Message-----
From: Tibert, Brock [mailto:[hidden email]]
Sent: Sunday, May 03, 2009 12:58 PM
To: 'ViAnn Beadle'
Subject: RE: Custom Format Time Variable

Thanks for taking the time to respond.  Maybe I am missing something, but
even on page 63 of the command syntax reference (V17), I do not see how I
can modify/create syntax to make my variable mm:ss. I am not a professional
syntax writer, but typically can work my way through it.

I tried using the Date/Time wizard but keep getting an error.  The syntax
that is returned is:

COMPUTE  time=TIME.HMS(0, mins, secs).

But I am getting an error telling me that there is an invalid combination of
data types, yet mins and seconds (my two variables) are numeric.

Thanks,

Brock

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Custom Format Time Variable

Brock-15
In reply to this post by Brock-15
This is the syntax I have been running to extract the mins/seconds and try
to create a new variable.  You can see that when the data are read into
SPSS, a time may be:

18:46, or
3:20, or
0:17

and is originally stored as a string.


STRING  mins (A2).
COMPUTE mins=CHAR.SUBSTR(Time,1,CHAR.INDEX(Time,':')-1).
EXECUTE.


STRING  secs (A2).
COMPUTE secs=CHAR.SUBSTR(Time,CHAR.INDEX(Time,':')+1,length(Time) -
CHAR.INDEX(Time,':')).
EXECUTE.


ALTER TYPE  mins(F2.0).
ALTER TYPE  secs(F2.0).
FORMATS  mins(F2.0).
FORMATS  secs(F2.0).
EXECUTE.

COMPUTE  time=TIME.HMS(0, mins, secs).
VARIABLE LABELS  time "".
VARIABLE LEVEL  time (SCALE).
FORMATS  time (TIME8).
VARIABLE WIDTH  time(8).
EXECUTE.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Custom Format Time Variable

ViAnn Beadle
You are trying to replace values in variable time which is a string with
numeric values in

COMPUTE time=TIME.HMS...

Although SPSS retains case when storing variable names, comparisons are case
insensitive so Time == time.

Change your output variable to some new variable name.

-----Original Message-----
From: Brock [mailto:[hidden email]]
Sent: Sunday, May 03, 2009 1:41 PM
To: [hidden email]; ViAnn Beadle
Subject: Re: Custom Format Time Variable

This is the syntax I have been running to extract the mins/seconds and try
to create a new variable.  You can see that when the data are read into
SPSS, a time may be:

18:46, or
3:20, or
0:17

and is originally stored as a string.


STRING  mins (A2).
COMPUTE mins=CHAR.SUBSTR(Time,1,CHAR.INDEX(Time,':')-1).
EXECUTE.


STRING  secs (A2).
COMPUTE secs=CHAR.SUBSTR(Time,CHAR.INDEX(Time,':')+1,length(Time) -
CHAR.INDEX(Time,':')).
EXECUTE.


ALTER TYPE  mins(F2.0).
ALTER TYPE  secs(F2.0).
FORMATS  mins(F2.0).
FORMATS  secs(F2.0).
EXECUTE.

COMPUTE  time=TIME.HMS(0, mins, secs).
VARIABLE LABELS  time "".
VARIABLE LEVEL  time (SCALE).
FORMATS  time (TIME8).
VARIABLE WIDTH  time(8).
EXECUTE.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Custom Format Time Variable

Brock-15
In reply to this post by Brock-15
I am sorry, as this is probably much easier than I am making it out to be,
but I am lost.  I am passing three numeric values in the time.hms function,
and that is where I am getting the error stating that I am using an invalid
combination of variables.

I looked up the function just to make sure I understood the function
correctly, and it says that it requires numeric values.

My apologies, but I guess I do not understand what I am doing incorrectly,
especially since the syntax was generated from the GUI.

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Custom Format Time Variable

Brock-15
In reply to this post by Brock-15
I apologize for the frustration, but I just changed the variable name as you
said.  I was getting hung up on the error message.

Thanks,

Brock

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Custom Format Time Variable

Art Kendall
In reply to this post by Brock-15
Open a new instance of SPSS.  Copy the syntax below to a syntax file.
Click <run>. Click <all>.
Is this what you are looking for?

data list list/ ms_string (a5).
begin data
18:46
3:20
0:17
end data.
string hms_string (a7).
compute hms_string = concat('0:',ms_string).
compute timelapse= number(hms_string,time7.0).
format timelapse(time7).
list.

Art Kendall
Social Research Consultants



Brock wrote:

> This is the syntax I have been running to extract the mins/seconds and try
> to create a new variable.  You can see that when the data are read into
> SPSS, a time may be:
>
> 18:46, or
> 3:20, or
> 0:17
>
> and is originally stored as a string.
>
>
> STRING  mins (A2).
> COMPUTE mins=CHAR.SUBSTR(Time,1,CHAR.INDEX(Time,':')-1).
> EXECUTE.
>
>
> STRING  secs (A2).
> COMPUTE secs=CHAR.SUBSTR(Time,CHAR.INDEX(Time,':')+1,length(Time) -
> CHAR.INDEX(Time,':')).
> EXECUTE.
>
>
> ALTER TYPE  mins(F2.0).
> ALTER TYPE  secs(F2.0).
> FORMATS  mins(F2.0).
> FORMATS  secs(F2.0).
> EXECUTE.
>
> COMPUTE  time=TIME.HMS(0, mins, secs).
> VARIABLE LABELS  time "".
> VARIABLE LEVEL  time (SCALE).
> FORMATS  time (TIME8).
> VARIABLE WIDTH  time(8).
> EXECUTE.
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> [hidden email] (not to SPSSX-L), with no body text except the
> command. To leave the list, send the command
> SIGNOFF SPSSX-L
> For a list of commands to manage subscriptions, send the command
> INFO REFCARD
>
>

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Custom Format Time Variable

Brock-15
In reply to this post by Brock-15
Thanks for your help!  For me, all I did was change the variable name from
"time" to something else.

- Brock

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD