Login  Register

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

Posted by David Marso on Feb 08, 2013; 2:05pm
URL: http://spssx-discussion.165.s1.nabble.com/creating-half-hourly-interval-numeric-variable-from-a-time-variable-tp5717982p5717985.html

"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?"