|
I have a string variable (repost) which can either look like this:
PA15 1A or
PA1 5A - both of which are different
what I want to do is to end up with
PA15 1 and
PA1 5
I can get
'PA15 ' with space or
'PA1 5'
but not what I want I know I can compute using
SUBSTR(strexpr,pos,length). but does not work for unequal lengths
Dr Muir Houston
Lecturer
DACE
Faculty of Education
University of Glasgow
0141-330-4699 |
|
What is the goal? Remove all instances of
a trailing capital A? Remove all instances of a single trailing letter? From: SPSSX(r)
Discussion [mailto:[hidden email]] On
Behalf Of Muir Houston I have a string variable
(repost) which can either look like this: PA15 1A or PA1 5A - both of which are different what I want to do is to end up with PA15 1 and PA1 5 I can get 'PA15 ' with space or 'PA1 5' but not what I want I know I can compute using SUBSTR(strexpr,pos,length). but does not work for unequal
lengths Dr Muir Houston Lecturer DACE Faculty of Education University of Glasgow 0141-330-4699 |
|
Try using the substr function within a DO IF structure: ** NOT tested. STRING newvar (A6). DO IF SUBSTR(var,4,1) = ‘5’. COMPUTE newvar = SUBSTR(var,1,6). ELSE. /* else if when there are multiple conditions. COMPUTE newvar = SUBSTR(var,1,5). END IF. --jim From: SPSSX(r) Discussion
[mailto:[hidden email]] On Behalf Of Oliver, Richard What is the goal? Remove all instances of a trailing capital A?
Remove all instances of a single trailing letter? From: SPSSX(r) Discussion
[mailto:[hidden email]] On Behalf Of Muir Houston I have a string variable (repost) which can either look like
this: PA15
1A or PA1
5A - both of which are different what
I want to do is to end up with PA15
1 and PA1
5 I
can get 'PA15
' with space or 'PA1
5' but
not what I want I know I can compute using SUBSTR(strexpr,pos,length).
but does not work for unequal lengths Dr Muir Houston Lecturer DACE Faculty
of Education University
of Glasgow 0141-330-4699 |
|
If the goal is to remove the last
non-blank character/or digit, the following works in release 16 or later: data list free (",") /stringvar
(a10). begin data abc def,123 456,ab1 c2,a1 c2b end data. compute #lastchar=char.length(stringvar). compute stringvar=substr(stringvar, 1,
#lastchar-1). list. From: SPSSX(r)
Discussion [mailto:[hidden email]] On
Behalf Of Marks, Jim Try using the substr
function within a DO IF structure: ** NOT tested. STRING newvar (A6). DO IF
SUBSTR(var,4,1) = ‘5’. COMPUTE newvar =
SUBSTR(var,1,6). ELSE. /* else
if when there are multiple conditions. COMPUTE newvar =
SUBSTR(var,1,5). END IF. --jim From: SPSSX(r)
Discussion [mailto:[hidden email]] On
Behalf Of Oliver, Richard What is the goal? Remove all instances of
a trailing capital A? Remove all instances of a single trailing letter? From: SPSSX(r)
Discussion [mailto:[hidden email]] On
Behalf Of Muir Houston I have a string variable
(repost) which can either look like this: PA15 1A or PA1 5A - both of which are different what I want to do is to end up with PA15 1 and PA1 5 I can get 'PA15 ' with space or 'PA1 5' but not what I want I know I can compute using SUBSTR(strexpr,pos,length). but does not work for unequal
lengths Dr Muir Houston Lecturer DACE Faculty of Education University of Glasgow 0141-330-4699 |
|
If you just want to remove all trailing "A"s, you could also use:
string newstring (a10). compute newstring = rtrim(rtrim(stringvar), "A"). By the way, what does "char.length" mean, or in what respect does it differ from the good ol' LENGTH? When was it introduced in Spss? Cheers!! Albert-Jan --- On Fri, 2/20/09, Oliver, Richard <[hidden email]> wrote: > From: Oliver, Richard <[hidden email]> > Subject: Re: trim strings of unequal length > To: [hidden email] > Date: Friday, February 20, 2009, 7:17 PM > If the goal is to remove the last non-blank character/or > digit, the following works in release 16 or later: > > > > data list free (",") /stringvar (a10). > > begin data > > abc def,123 456,ab1 c2,a1 c2b > > end data. > > compute #lastchar=char.length(stringvar). > > compute stringvar=substr(stringvar, 1, #lastchar-1). > > list. > > > > ________________________________ > > From: SPSSX(r) Discussion [mailto:[hidden email]] > On Behalf Of Marks, Jim > Sent: Friday, February 20, 2009 11:33 AM > To: [hidden email] > Subject: Re: trim strings of unequal length > > > > Try using the substr function within a DO IF structure: > > > > ** NOT tested. > > STRING newvar (A6). > > > > DO IF SUBSTR(var,4,1) = '5'. > > COMPUTE newvar = SUBSTR(var,1,6). > > ELSE. /* else if when there are multiple conditions. > > COMPUTE newvar = SUBSTR(var,1,5). > > END IF. > > > > --jim > > > > From: SPSSX(r) Discussion [mailto:[hidden email]] > On Behalf Of Oliver, Richard > Sent: Friday, February 20, 2009 11:21 AM > To: [hidden email] > Subject: Re: trim strings of unequal length > > > > What is the goal? Remove all instances of a trailing > capital A? Remove all instances of a single trailing letter? > > > > > ________________________________ > > From: SPSSX(r) Discussion [mailto:[hidden email]] > On Behalf Of Muir Houston > Sent: Friday, February 20, 2009 9:42 AM > To: [hidden email] > Subject: trim strings of unequal length > > > > I have a string variable (repost) which can either look > like this: > > PA15 1A or > > PA1 5A - both of which are different > > > > what I want to do is to end up with > > > > PA15 1 and > > PA1 5 > > > > I can get > > 'PA15 ' with space or > > 'PA1 5' > > > > but not what I want I know I can compute using > > > > SUBSTR(strexpr,pos,length). but does not work for unequal > lengths > > > > > > > > > > Dr Muir Houston > > Lecturer > > DACE > > Faculty of Education > > University of Glasgow > > 0141-330-4699 ===================== 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 |
|
Hi all,
I think i know what i need to do in words but am having difficulty translating this into syntax. I have a file that contains: Begin date Begin time of day (24hr time) Completion time of day (24hr time) The begin date and time are the same for all cases. I need to compute hours between the completion time and the begin time. the problem is that the number of hours can exceed 24 hours so we get into the next day. The time in hours can range between 10 and 32. Sample data. The Total Time is my desired computation: ID Begin date Begin time of day End time of day Total Time in hours 1 1/1/08 07:00 18:00 11:00 2 1/1/08 07:00 23:59 16:59 3 1/1/08 07:00 02:00 19:00 4 1/1/08 07:00 06:00 23:00 So, for cases 1 and 2, it's a simple computation. But for cases 3 and 4, the completion times are the next day. What i think i need to do is: 1) Covert the end time of day into a dd-mm-yyyy hh:mm field by first creating a new variable called EndDate if end time of day GE 17:00 and LE 23:59 then EndDate=Begin Date if end time of day GE 24:00 and LE 15:00 then EndDate=Begin Date + 1 day 2) combine these fields: Compute EndDateTime = EndDate+End Time of day 3) Do the subtraction to get the number of hours. Is this the correct thought process and if so, can someone help me out with the syntax to accomplish 1) and 2) above? thanks a bunch Carol ===================== 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 |
|
Hi!
Something like this? Cheers!! Albert-Jan data list free / t1 (time11). begin data '18:00' '23:59' '02:00' '06:00' end data. numeric t0 duration (time11). compute t0 = 7 * 60 * 60. compute #midnight = 24 * 60 * 60. compute duration = t1 - t0. if (t1 < t0) duration = #midnight - t0 + t1. exe. --- On Fri, 3/13/09, Parise, Carol A. <[hidden email]> wrote: > From: Parise, Carol A. <[hidden email]> > Subject: time in hh:mm over more than 24 hrs > To: [hidden email] > Date: Friday, March 13, 2009, 11:15 PM > Hi all, > > I think i know what i need to do in words but am having > difficulty > translating this into syntax. > > I have a file that contains: > > Begin date > Begin time of day (24hr time) > Completion time of day (24hr time) > > The begin date and time are the same for all cases. I need > to compute > hours between the completion time and the begin time. the > problem is > that the number of hours can exceed 24 hours so we get into > the next > day. The time in hours can range between 10 and 32. > > Sample data. The Total Time is my desired computation: > > ID Begin date Begin > time of day End time of day > Total Time in hours > 1 1/1/08 > 07:00 > 18:00 > 11:00 > 2 1/1/08 > 07:00 > 23:59 > 16:59 > 3 1/1/08 > 07:00 > 02:00 > 19:00 > 4 1/1/08 > 07:00 > 06:00 > 23:00 > > So, for cases 1 and 2, it's a simple computation. But for > cases 3 and 4, > the completion times are the next day. > > What i think i need to do is: > > 1) Covert the end time of day into a dd-mm-yyyy hh:mm field > by first > creating a new variable called EndDate > > if end time of day GE > 17:00 and LE 23:59 then EndDate=Begin > Date > if end time of day GE > 24:00 and LE 15:00 then EndDate=Begin > Date + 1 day > > 2) combine these fields: > Compute EndDateTime = > EndDate+End Time of day > > 3) Do the subtraction to get the number of hours. > > Is this the correct thought process and if so, can someone > help me out > with the syntax to accomplish 1) and 2) above? > > thanks a bunch > Carol > > > > > ===================== > 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 |
|
This worked great! ...and with much less syntax and fewer steps than what i thought i needed to do.
I don't know how i did my job before this list :-). Thanks a bunch Carol -----Original Message----- From: Albert-jan Roskam [mailto:[hidden email]] Sent: Saturday, March 14, 2009 3:48 AM To: [hidden email]; Parise, Carol A. Subject: Re: time in hh:mm over more than 24 hrs Hi! Something like this? Cheers!! Albert-Jan data list free / t1 (time11). begin data '18:00' '23:59' '02:00' '06:00' end data. numeric t0 duration (time11). compute t0 = 7 * 60 * 60. compute #midnight = 24 * 60 * 60. compute duration = t1 - t0. if (t1 < t0) duration = #midnight - t0 + t1. exe. --- On Fri, 3/13/09, Parise, Carol A. <[hidden email]> wrote: > From: Parise, Carol A. <[hidden email]> > Subject: time in hh:mm over more than 24 hrs > To: [hidden email] > Date: Friday, March 13, 2009, 11:15 PM Hi all, > > I think i know what i need to do in words but am having difficulty > translating this into syntax. > > I have a file that contains: > > Begin date > Begin time of day (24hr time) > Completion time of day (24hr time) > > The begin date and time are the same for all cases. I need to compute > hours between the completion time and the begin time. the problem is > that the number of hours can exceed 24 hours so we get into the next > day. The time in hours can range between 10 and 32. > > Sample data. The Total Time is my desired computation: > > ID Begin date Begin > time of day End time of day > Total Time in hours > 1 1/1/08 > 07:00 > 18:00 > 11:00 > 2 1/1/08 > 07:00 > 23:59 > 16:59 > 3 1/1/08 > 07:00 > 02:00 > 19:00 > 4 1/1/08 > 07:00 > 06:00 > 23:00 > > So, for cases 1 and 2, it's a simple computation. But for cases 3 and > 4, the completion times are the next day. > > What i think i need to do is: > > 1) Covert the end time of day into a dd-mm-yyyy hh:mm field by first > creating a new variable called EndDate > > if end time of day GE > 17:00 and LE 23:59 then EndDate=Begin Date > if end time of day GE > 24:00 and LE 15:00 then EndDate=Begin Date + 1 day > > 2) combine these fields: > Compute EndDateTime = > EndDate+End Time of day > > 3) Do the subtraction to get the number of hours. > > Is this the correct thought process and if so, can someone help me out > with the syntax to accomplish 1) and 2) above? > > thanks a bunch > Carol > > > > > ===================== > 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 |
| Free forum by Nabble | Edit this page |
