creating half hourly interval numeric variable from a time variable

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

creating half hourly interval numeric variable from a time variable

Paul Mcgeoghan
Hi,

I have a time variable StartTime hh:mm:ss.
I need to work out a new numeric variable so that between 00:00 and 00:29,
it will be 1; between 00:30 and 00:59, it will be 2; etc.
So I have syntax such as:

COMPUTE hourperiod=XDATE.HOUR(StartTime).
EXECUTE.
COMPUTE minperiod=XDATE.MINUTE(StartTime).
EXECUTE.
IF  (hourperiod=0 & minperiod<30) period=1.
EXECUTE.
IF  (hourperiod=0 & minperiod>=30) period=2.
EXECUTE.

It doesn't seem to like this syntax though.
I get errors:
IF  (hourperiod=0 & minperiod<30) period=1.
EXECUTE.
>Warning # 142.  Command name: EXECUTE
>LOOP has no effect on this command.

>Error # 4095.  Command name: EXECUTE
>The transformations program contains an unclosed LOOP, DO IF, or complex
file
>structure.  Use the level-of-control shown to the left of the SPSS
Statistics
>commands to determine the range of LOOPs and DO IFs.
>Execution of this command stops.

Is this the best way to achieve this?

=====================
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: creating half hourly interval numeric variable from a time variable

David Marso
Administrator
"Is this the best way to achieve this?"
Err, I would say absolutely NOT!!!
And get rid of all those unnecessary EXE statements.
--

** Method 1 **.
COMPUTE SEG=SUM(XDATE.HOUR(MyTime) * 2, (XDATE.MINUTE(MyTime) GT 29), 1) .

** Method 2 **.
COMPUTE SEG2=TRUNC(MyTime/1800)+1.


Paul Mcgeoghan wrote
Hi,

I have a time variable StartTime hh:mm:ss.
I need to work out a new numeric variable so that between 00:00 and 00:29,
it will be 1; between 00:30 and 00:59, it will be 2; etc.
So I have syntax such as:

COMPUTE hourperiod=XDATE.HOUR(StartTime).
EXECUTE.
COMPUTE minperiod=XDATE.MINUTE(StartTime).
EXECUTE.
IF  (hourperiod=0 & minperiod<30) period=1.
EXECUTE.
IF  (hourperiod=0 & minperiod>=30) period=2.
EXECUTE.

It doesn't seem to like this syntax though.
I get errors:
IF  (hourperiod=0 & minperiod<30) period=1.
EXECUTE.
>Warning # 142.  Command name: EXECUTE
>LOOP has no effect on this command.

>Error # 4095.  Command name: EXECUTE
>The transformations program contains an unclosed LOOP, DO IF, or complex
file
>structure.  Use the level-of-control shown to the left of the SPSS
Statistics
>commands to determine the range of LOOPs and DO IFs.
>Execution of this command stops.

Is this the best way to achieve this?

=====================
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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: creating half hourly interval numeric variable from a time variable

Art Kendall
In reply to this post by Paul Mcgeoghan
It sound like you have a LOOP or something before the execute.

See if this example syntax does what you want.
I do not know what you meant by "etc".  Can you cobble together an example syntax set of data that shows what you want?

data list list /starttime (time8) want (f2).
begin data
00:12:01 1
11:03:01 1
00:32:30 2
02:29:58 1
05:30:01 2
18:06:33 1
14:45:33 2
02:23:01 1
end data.
COMPUTE minperiod=XDATE.MINUTE(StartTime).
compute period=-1.
IF  (minperiod lt 30) period=1.
IF  (minperiod ge 30) period=2.
formats period (f2).
missing values period(-1).
list varaibles = starttime want  period.


Art Kendall
Social Research Consultants
On 2/8/2013 7:56 AM, Paul McGeoghan wrote:
Hi,

I have a time variable StartTime hh:mm:ss.
I need to work out a new numeric variable so that between 00:00 and 00:29,
it will be 1; between 00:30 and 00:59, it will be 2; etc.
So I have syntax such as:

COMPUTE hourperiod=XDATE.HOUR(StartTime).
EXECUTE.
COMPUTE minperiod=XDATE.MINUTE(StartTime).
EXECUTE.
IF  (hourperiod=0 & minperiod<30) period=1.
EXECUTE.
IF  (hourperiod=0 & minperiod>=30) period=2.
EXECUTE.

It doesn't seem to like this syntax though.
I get errors:
IF  (hourperiod=0 & minperiod<30) period=1.
EXECUTE.
Warning # 142.  Command name: EXECUTE
LOOP has no effect on this command.

      
Error # 4095.  Command name: EXECUTE
The transformations program contains an unclosed LOOP, DO IF, or complex
file
structure.  Use the level-of-control shown to the left of the SPSS
Statistics
commands to determine the range of LOOPs and DO IFs.
Execution of this command stops.
Is this the best way to achieve this?

=====================
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: creating half hourly interval numeric variable from a time variable

David Marso
Administrator
In reply to this post by David Marso
** Method 3 **.
COMPUTE SEG3=TRUNC(MyTime/TIME.HMS(0,30,0))+1.
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Automatic reply: creating half hourly interval numeric variable from a time variable

Kelly Vander Ley

I am out of the office and have limited availability to respond to email from February 5th-12th. If you need immediate assistance please call the main office number 503/223-8248 or 800/788-1887 and an office assistant will ensure that your need is addressed. 

 

Kelly