regrouping date entries

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

regrouping date entries

Donna-28
Hi Everyone,

My data skills are rusty & I am having trouble either sequencing commands
or choosing the right options to get the results.  The data include call
center tracking variables: participant ID (ID), Atempt No (Att#) Date of
Attempt (Date) and Outcome Code (Outcome)and look like this in SPSS:

    ID         Att#      Date                Outcome
0706-1000-1-1b  1 05-JUL-2007       10.2
0706-1000-1-1b  2 06-JUL-2007       10.2
0706-1000-1-1b  3 09-JUL-2007       10.2
0706-1000-1-1b  4 10-JUL-2007       50.1
0475-2458-2-1b  1 08-AUG-2007       10.2
0475-2458-2-1b  2 10-AUG-2007       40.1
0674-1344-3-1b  1 07-SEP-2007       10.2
0674-1344-3-1b  2 07-SEP-2007           10.2
0674-1344-3-1b  3 18-SEP-2007       50.1
0674-1344-3-1b  4 25-JAN-2008       50.1

I am interested in knowing # of attempts per month for a 60 month study --
there will be multiple IDs contacted on the same date and multiple attempts
for those multiple IDs -- and then outcome by month by code.

I have been working on the first part of the report, but am getting an
error that I can't for the life of me figure out, having tried all sorts of
changes.  Any help would be appreciated!

Syntax:
loop #m = 1 to 60.
if (contact_date >= date.dmmmyyyy(01,01+3m,2007) & contact_date <
date.dmmmyyyy(01,30+#m,2007)) cont_m = #m.
end loop.
execute.

Error Message:
Error # 4033 in column 21.  Text: date.dmmmyyyy
>A function name is followed by a decimal point and a function modifier.
>However, the modifier is misspelled or invalid.


Thanks,
Donna

=====================
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: regrouping date entries

ViAnn Beadle
I'm not sure why you're approaching this through transformations. Why can't
you just extract the month and year from the date variable as a variable run
frequencies on that.

Your getting errors in your IF statement because there is no such function
as date.dmmmyyyy. I think you mean date.dmy.

My approach would be something like this:

Compute #month=xdate.month(date).
Compute #year=xdate.year(date).
Compute yearmonth=date.moyr(#month,#date).
Formats yearmonth(moyr8).
Frequencies var yearmonth.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Donna
Sent: Wednesday, February 13, 2008 2:35 PM
To: [hidden email]
Subject: regrouping date entries
Hi Everyone,

My data skills are rusty & I am having trouble either sequencing commands
or choosing the right options to get the results.  The data include call
center tracking variables: participant ID (ID), Atempt No (Att#) Date of
Attempt (Date) and Outcome Code (Outcome)and look like this in SPSS:

    ID         Att#      Date                Outcome
0706-1000-1-1b  1 05-JUL-2007       10.2
0706-1000-1-1b  2 06-JUL-2007       10.2
0706-1000-1-1b  3 09-JUL-2007       10.2
0706-1000-1-1b  4 10-JUL-2007       50.1
0475-2458-2-1b  1 08-AUG-2007       10.2
0475-2458-2-1b  2 10-AUG-2007       40.1
0674-1344-3-1b  1 07-SEP-2007       10.2
0674-1344-3-1b  2 07-SEP-2007           10.2
0674-1344-3-1b  3 18-SEP-2007       50.1
0674-1344-3-1b  4 25-JAN-2008       50.1

I am interested in knowing # of attempts per month for a 60 month study --
there will be multiple IDs contacted on the same date and multiple attempts
for those multiple IDs -- and then outcome by month by code.

I have been working on the first part of the report, but am getting an
error that I can't for the life of me figure out, having tried all sorts of
changes.  Any help would be appreciated!

Syntax:
loop #m = 1 to 60.
if (contact_date >= date.dmmmyyyy(01,01+3m,2007) & contact_date <
date.dmmmyyyy(01,30+#m,2007)) cont_m = #m.
end loop.
execute.

Error Message:
Error # 4033 in column 21.  Text: date.dmmmyyyy
>A function name is followed by a decimal point and a function modifier.
>However, the modifier is misspelled or invalid.


Thanks,
Donna

=====================
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: regrouping date entries

Marks, Jim
In reply to this post by Donna-28
try DATE.DMY in your IF statement

-jim

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Donna
Sent: Wednesday, February 13, 2008 3:35 PM
To: [hidden email]
Subject: regrouping date entries

Hi Everyone,

My data skills are rusty & I am having trouble either sequencing
commands or choosing the right options to get the results.  The data
include call center tracking variables: participant ID (ID), Atempt No
(Att#) Date of Attempt (Date) and Outcome Code (Outcome)and look like
this in SPSS:

    ID         Att#      Date                Outcome
0706-1000-1-1b  1 05-JUL-2007       10.2
0706-1000-1-1b  2 06-JUL-2007       10.2
0706-1000-1-1b  3 09-JUL-2007       10.2
0706-1000-1-1b  4 10-JUL-2007       50.1
0475-2458-2-1b  1 08-AUG-2007       10.2
0475-2458-2-1b  2 10-AUG-2007       40.1
0674-1344-3-1b  1 07-SEP-2007       10.2
0674-1344-3-1b  2 07-SEP-2007           10.2
0674-1344-3-1b  3 18-SEP-2007       50.1
0674-1344-3-1b  4 25-JAN-2008       50.1

I am interested in knowing # of attempts per month for a 60 month study
-- there will be multiple IDs contacted on the same date and multiple
attempts for those multiple IDs -- and then outcome by month by code.

I have been working on the first part of the report, but am getting an
error that I can't for the life of me figure out, having tried all sorts
of changes.  Any help would be appreciated!

Syntax:
loop #m = 1 to 60.
if (contact_date >= date.dmmmyyyy(01,01+3m,2007) & contact_date <
date.dmmmyyyy(01,30+#m,2007)) cont_m = #m.
end loop.
execute.

Error Message:
Error # 4033 in column 21.  Text: date.dmmmyyyy
>A function name is followed by a decimal point and a function modifier.
>However, the modifier is misspelled or invalid.


Thanks,
Donna

=====================
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
|

Extracting Time, Time Zone from a String Variable

Harrington, Donna
In reply to this post by ViAnn Beadle
Hi,
I want to analyze time and time zone data that was entered as one string variable. I am not sure how best to do this.  The data looks like this:

2:52 pm PT
3:35 pm PST
6:35 pm CT
1:13 pm CT
9:48 am HST
6:13 pm EDT
3:55 pm ET
2:15 pm AKT
12:33 pm AST

I created timevar for a 24 hour clock (below) but do not the best way to cover the 10 different timezones used in data entry.  Any suggestions?

COMPUTE timevar=NUMBER(SUBSTR(time,1,5),TIME8).
IF INDEX(UPCASE(time),PM ne 0 timevar=timevar+(12*60).
FORMATS timevar (time8).
COMPUTE xtimevar=100*xdate.hour(timevar) + xdate.minute(timevar).

Thanks in advance,

=====================
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: Extracting Time, Time Zone from a String Variable

Richard Ristow
At 12:48 PM 3/5/2008, Harrington, Donna wrote:

>I want to analyze time and time zone data that was entered as one
>string variable. The data looks like this:

|-----------------------------|---------------------------|
|Output Created               |06-MAR-2008 00:36:49       |
|-----------------------------|---------------------------|
TimeString

2:52 pm PT
3:35 pm PST
6:35 pm CT
1:13 pm CT
9:48 am HST
6:13 pm EDT
3:55 pm ET
2:15 pm AKT
12:33 pm AST
12:33 am AST

Number of cases read:  10    Number of cases listed:  10

*  I.     Parse the string into its components. Convert the    ...... .
*         time field to an SPSS time variable.                        .

NUMERIC  Time12    (TIME6).
STRING   AM.PM     (A3)
          Zone      (A5).

STRING   #Parsing  (A30).
NUMERIC  #Index    (F4).

COMPUTE  #Parsing = LTRIM(TimeString).

*  I.A.    Extract time portion, and convert to a time value  ...... .
COMPUTE   #Index   = INDEX(#Parsing,' ').
COMPUTE   Time12   = NUMBER(SUBSTR(#Parsing,1,#Index),
                            TIME6).
*  ....    Drop the time portion from the string              ...... .
COMPUTE   #Parsing = LTRIM(SUBSTR(#Parsing,#Index)).

*  I.B.    Extract 'am/pm'                                    ...... .
COMPUTE   #Index   = INDEX(#Parsing,' ').
COMPUTE   AM.PM    = SUBSTR(#Parsing,1,#Index).
*  ....    Drop AM/PM            from the string              ...... .
COMPUTE   #Parsing = LTRIM(SUBSTR(#Parsing,#Index)).

*  I.C.   The rest is time zone                               ...... .
COMPUTE  Zone     = #Parsing.

LIST.

List
|-----------------------------|---------------------------|
|Output Created               |06-MAR-2008 00:36:49       |
|-----------------------------|---------------------------|
TimeString        Time12 AM.PM Zone

2:52 pm PT          2:52 pm    PT
3:35 pm PST         3:35 pm    PST
6:35 pm CT          6:35 pm    CT
1:13 pm CT          1:13 pm    CT
9:48 am HST         9:48 am    HST
6:13 pm EDT         6:13 pm    EDT
3:55 pm ET          3:55 pm    ET
2:15 pm AKT         2:15 pm    AKT
12:33 pm AST       12:33 pm    AST
12:33 am AST       12:33 am    AST

Number of cases read:  10    Number of cases listed:  10


II. Convert to 24-hour clock

>I created timevar for a 24 hour clock:
>
>COMPUTE timevar=NUMBER(SUBSTR(time,1,5),TIME8).
>IF INDEX(UPCASE(time),PM ne 0 timevar=timevar+(12*60).
>FORMATS timevar (time8).

This won't work:
>IF INDEX(UPCASE(time),PM ne 0 timevar=timevar+(12*60).

A. "PM" should be a character string value ('PM'), and should be
followed by two right parentheses: "INDEX(UPCASE(time),'PM') ne 0".

B. "(12*60)" isn't the correct expression for "12 hours". SPSS times
are in seconds; use "(12*60*60)", or "(12*3600)", or (best) "TIME.HMS(12)".

C. Finally, the logic is incorrect for times between midnight and
1:00 am, and between noon and 1:00 pm.; see the last two lines in the
listing, below.

*  II.   Convert time from 12-hour to 24-hour clock           ...... .

*  II.A.  This doesn't work:                                  ...... .
COMPUTE timevar=NUMBER(SUBSTR(LTRIM(TimeString),1,5),Time8).
IF INDEX(UPCASE(TimeString),'PM') ne 0
         timevar=timevar+(12*60*60).
FORMATS timevar (time6).

*  II.B.  This does:                                          ...... .
NUMERIC  Time24    (Time6).
DO IF   UPCASE(AM.PM) eq 'AM' AND Time12 GE TIME.HMS(12).
.  COMPUTE Time24 = Time12 - TIME.HMS(12).
ELSE IF UPCASE(AM.PM) eq 'AM'.
.  COMPUTE Time24 = Time12.
ELSE IF UPCASE(AM.PM) eq 'PM' AND Time12 GE TIME.HMS(12).
.  COMPUTE Time24 = Time12.
ELSE IF UPCASE(AM.PM) eq 'PM'.
.  COMPUTE Time24 = Time12 + TIME.HMS(12).
END IF.

LIST.

List
|-----------------------------|---------------------------|
|Output Created               |06-MAR-2008 00:36:50       |
|-----------------------------|---------------------------|
TimeString        Time12 AM.PM Zone  timevar Time24

2:52 pm PT          2:52 pm    PT      14:52  14:52
3:35 pm PST         3:35 pm    PST     15:35  15:35
6:35 pm CT          6:35 pm    CT      18:35  18:35
1:13 pm CT          1:13 pm    CT      13:13  13:13
9:48 am HST         9:48 am    HST      9:48   9:48
6:13 pm EDT         6:13 pm    EDT     18:13  18:13
3:55 pm ET          3:55 pm    ET      15:55  15:55
2:15 pm AKT         2:15 pm    AKT     14:15  14:15
12:33 pm AST       12:33 pm    AST     24:33  12:33
12:33 am AST       12:33 am    AST     12:33   0:33

Number of cases read:  10    Number of cases listed:  10


III. Convert to a single time zone

>... but I do not the best way to cover the 10 different timezones
>used in data entry.

You can convert all times to UT (what used to be called Greenwich
Mean Time), or any other single zone you prefer:

*  III.  Convert time from local zone to Universal            ...... .

NUMERIC TimeUT     (TIME6)
         DaysDiff   (F2).
VAR LABEL
         DaysDiff  'How much UT date differs from local date'.


*  III.A. Convert time zone to difference from UT             ...... .

*  ...... Table taken from                                    ...... .
*         http://www.timetemperature.com/tzus
*               /time_zone_codes_us.shtml
*         Expand and correct as needed                               .

NUMERIC #UT_Diff (F3).
RECODE  ZONE
        ('PT','PST'   /* Pacific Standard Time   (US)  */  = -8)
        ('CT','CST'   /* Central Standard Time   (US)  */  = -6)
        ('ET','EST'   /* Eastern Standard Time   (US)  */  = -5)
        ('EDT','EDST' /* Eastern Daylight Saving (US)  */  = -4)
        ('HST'        /* HAWAII-ALEUTIAN STANDARD TIME */  = -10)
        ('AKT','AKST' /* ALASKAN STANDARD TIME         */  = -9)
        ('AST'        /* ATLANTIC STANDARD TIME         */  = -4)
        INTO #UT_Diff.


*  III.B. Apply the differences, to get time in UT            ...... .

COMPUTE TimeUT = Time24 - TIME.HMS(#UT_Diff).

DO IF   TimeUT LT 0.
.  COMPUTE DaysDiff = -1.
.  COMPUTE TimeUT   = TimeUT + TIME.HMS(24).
ELSE IF TimeUT GT TIME.HMS(24).
.  COMPUTE DaysDiff =  1.
.  COMPUTE TimeUT   = TimeUT - TIME.HMS(24).
ELSE.
.  COMPUTE DaysDiff = 0.
END IF.

LIST.

List
|-----------------------------|---------------------------|
|Output Created               |06-MAR-2008 00:36:51       |
|-----------------------------|---------------------------|
TimeString        Time12 AM.PM Zone  timevar Time24 TimeUT DaysDiff

2:52 pm PT          2:52 pm    PT      14:52  14:52  22:52     0
3:35 pm PST         3:35 pm    PST     15:35  15:35  23:35     0
6:35 pm CT          6:35 pm    CT      18:35  18:35   0:35     1
1:13 pm CT          1:13 pm    CT      13:13  13:13  19:13     0
9:48 am HST         9:48 am    HST      9:48   9:48  19:48     0
6:13 pm EDT         6:13 pm    EDT     18:13  18:13  22:13     0
3:55 pm ET          3:55 pm    ET      15:55  15:55  20:55     0
2:15 pm AKT         2:15 pm    AKT     14:15  14:15  23:15     0
12:33 pm AST       12:33 pm    AST     24:33  12:33  16:33     0
12:33 am AST       12:33 am    AST     12:33   0:33   4:33     0

Number of cases read:  10    Number of cases listed:  10

=============================
APPENDIX: Test data, and code
=============================
*  ................................................................. .
*  .................   Test data               ..................... .

*  "The data looks like this:"                                       .
DATA LIST FIXED /
    TimeString 04-20 (A).
BEGIN DATA
    2:52 pm PT
    3:35 pm PST
    6:35 pm CT
    1:13 pm CT
    9:48 am HST
    6:13 pm EDT
    3:55 pm ET
    2:15 pm AKT
    12:33 pm AST
    12:33 am AST
END DATA.

LIST.

*  .................   Post after this point   ..................... .
*  ................................................................. .

*  I.     Parse the string into its components. Convert the    ...... .
*         time field to an SPSS time variable.                        .

NUMERIC  Time12    (TIME6).
STRING   AM.PM     (A3)
          Zone      (A5).

STRING   #Parsing  (A30).
NUMERIC  #Index    (F4).

COMPUTE  #Parsing = LTRIM(TimeString).

*  I.A.    Extract time portion, and convert to a time value  ...... .
COMPUTE   #Index   = INDEX(#Parsing,' ').
COMPUTE   Time12   = NUMBER(SUBSTR(#Parsing,1,#Index),
                            TIME6).
*  ....    Drop the time portion from the string              ...... .
COMPUTE   #Parsing = LTRIM(SUBSTR(#Parsing,#Index)).

*  I.B.    Extract 'am/pm'                                    ...... .
COMPUTE   #Index   = INDEX(#Parsing,' ').
COMPUTE   AM.PM    = SUBSTR(#Parsing,1,#Index).
*  ....    Drop AM/PM            from the string              ...... .
COMPUTE   #Parsing = LTRIM(SUBSTR(#Parsing,#Index)).

*  I.C.   The rest is time zone                               ...... .
COMPUTE  Zone     = #Parsing.

LIST.


*  II.   Convert time from 12-hour to 24-hour clock           ...... .

*  II.A.  This doesn't work:                                  ...... .
COMPUTE timevar=NUMBER(SUBSTR(LTRIM(TimeString),1,5),Time8).
IF INDEX(UPCASE(TimeString),'PM') ne 0
         timevar=timevar+(12*60*60).
FORMATS timevar (time6).

*  II.B.  This does:                                          ...... .
NUMERIC  Time24    (Time6).
DO IF   UPCASE(AM.PM) eq 'AM' AND Time12 GE TIME.HMS(12).
.  COMPUTE Time24 = Time12 - TIME.HMS(12).
ELSE IF UPCASE(AM.PM) eq 'AM'.
.  COMPUTE Time24 = Time12.
ELSE IF UPCASE(AM.PM) eq 'PM' AND Time12 GE TIME.HMS(12).
.  COMPUTE Time24 = Time12.
ELSE IF UPCASE(AM.PM) eq 'PM'.
.  COMPUTE Time24 = Time12 + TIME.HMS(12).
END IF.

LIST.

*  III.  Convert time from local zone to Universal            ...... .

NUMERIC TimeUT     (TIME6)
         DaysDiff   (F2).
VAR LABEL
         DaysDiff  'How much UT date differs from local date'.


*  III.A. Convert time zone to difference from UT             ...... .

*  ...... Table taken from                                    ...... .
*         http://www.timetemperature.com/tzus
*               /time_zone_codes_us.shtml
*         Expand and correct as needed                               .

NUMERIC #UT_Diff (F3).
RECODE  ZONE
        ('PT','PST'   /* Pacific Standard Time   (US)  */  = -8)
        ('CT','CST'   /* Central Standard Time   (US)  */  = -6)
        ('ET','EST'   /* Eastern Standard Time   (US)  */  = -5)
        ('EDT','EDST' /* Eastern Daylight Saving (US)  */  = -4)
        ('HST'        /* HAWAII-ALEUTIAN STANDARD TIME */  = -10)
        ('AKT','AKST' /* ALASKAN STANDARD TIME         */  = -9)
        ('AST'        /* ATLANTIC STANDARD TIME         */  = -4)
        INTO #UT_Diff.


*  III.B. Apply the differences, to get time in UT            ...... .

COMPUTE TimeUT = Time24 - TIME.HMS(#UT_Diff).

DO IF   TimeUT LT 0.
.  COMPUTE DaysDiff = -1.
.  COMPUTE TimeUT   = TimeUT + TIME.HMS(24).
ELSE IF TimeUT GT TIME.HMS(24).
.  COMPUTE DaysDiff =  1.
.  COMPUTE TimeUT   = TimeUT - TIME.HMS(24).
ELSE.
.  COMPUTE DaysDiff = 0.
END IF.

LIST.

=====================
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: Extracting Time, Time Zone from a String Variable

Harrington, Donna
Hi Richard,

Thanks for putting me on a path towards resolving my problem.  I am having trouble, though, reproducing your output.  I will post in segments, if that is ok, as I want to be really clear in my learning.  For I a-c:

I understand all of the commands except:
>  NUMERIC Time12   (TIME6).  Why (Time6)?
>  NUMERIC #Index (F4).   Why (F4)?

Then, this is the output on my way to the same table you posted.
How should I understand the warnings?

Thanks,

Donna


NUMERIC Time12   (TIME6).
STRING   (AM.PM) (A3).

>Error # 4293 in column 10.  Text: (
>The variable list is empty.
>This command not executed.


>Error # 4361 in column 11.  Text: AM.PM
>The format contains a misplaced period.

STRING  Zone (A5).

STRING #Parsing (A30).
NUMERIC #Index (F4).

COMPUTE #Parsing = LTRIM (Contact_Time).

COMPUTE #Index = INDEX (#Parsing, ' ' ).
COMPUTE Time12 = NUMBER (SUBSTR(#Parsing,1,#Index), TIME6).

COMPUTE #Parsing = LTRIM (SUBSTR(#Parsing, #Index)).

COMPUTE #Index = INDEX (#Parsing, ' ').
COMPUTE AM.PM = SUBSTR(#Parsing,1,#Index).

>Error # 4309 in column 256.  Text: (End of Command)
>Invalid combination of data types in an assignment.  Character strings may
>only be assigned to string variables.  Numeric and logical quantities may
>only be assigned to numeric variables.  Consider using the STRING or NUMBER
>function.
>This command not executed.


COMPUTE #Parsing = LTRIM (SUBSTR(#Parsing,#Index)).

COMPUTE Zone = #Parsing.
LIST.

**************OUTPUT CREATED*************
*****************************************
contact_time Time12 Zone

2:52 pm PT     2:52 PT
3:35 pm PT     3:35 PT
3:37 pm PT     3:37 PT
1:35 pm PT     1:35 PT
3:39 pm PT     3:39 PT
3:41 pm PT     3:41 PT
3:43 pm PT     3:43 PT
6:35 pm CT     6:35 CT
1:13 pm CT     1:13 CT
1:41 pm CT     1:41 CT


Number of cases read:  10    Number of cases listed:  10

=====================
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: Extracting Time, Time Zone from a String Variable

Maguin, Eugene
Donna,

I think this command

STRING   (AM.PM) (A3).

Should be

STRING   AM.PM (A3).

Gene Maguin

=====================
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: Extracting Time, Time Zone from a String Variable

Richard Ristow
In reply to this post by Harrington, Donna
At 02:46 PM 3/7/2008, Harrington, Donna wrote:

>I am having trouble reproducing [Richard Ristow's] output.  I will
>post in segments, if that is ok, as I want to be really clear in my learning.

Yes; excellent practice.

>   For I a-c:
>
>I understand all of the commands except:
> >  NUMERIC Time12   (TIME6).  Why (Time6)?

That format displays time as "hh:mm", which matches your input (which
has hours and minutes, but not seconds): display form "12:33",
instead of Time9 to get "12:33:00". Your taste may vary.

> >  NUMERIC #Index (F4).   Why (F4)?

I use #Index as an index into string #Parsing, which begins as a copy
of string TimeString. And, yes, #Parsing is 30 characters long, so
#Index can be no larger than 30, and (F2) would do just fine. I used
"(F4)" following my own practice, to specify a format one or two
digits wider than can reasonably occur.

>How should I understand the warnings?
>
>NUMERIC Time12   (TIME6).
>STRING   (AM.PM) (A3).
>
>>Error # 4293 in column 10.  Text: (
>>The variable list is empty. This command not executed.
>>
>>Error # 4361 in column 11.  Text: AM.PM
>>The format contains a misplaced period.

Gene Maguin's got it just right:

>I think this command should be
>STRING   AM.PM (A3).

As you have it, there are two problems:
A. On NUMERIC or STRING (or FORMATS), format specifications are in
parentheses, and variable names are not. If you write "(AM.PM)", then
that's taken as a format specification, so
>>The variable list is empty.
i.e., no text outside parentheses; so, no variables; and
>>Error # 4361 in column 11.  Text: AM.PM
>>The format contains a misplaced period.
it tries to interpret "AM.PM" as a format specification, and of
course it's not valid.

[...]
>COMPUTE AM.PM = SUBSTR(#Parsing,1,#Index).
>
>>Error # 4309 in column 256.  Text: (End of Command)
>>Invalid combination of data types in an assignment.

That's call "propagation of errors" - one error makes other code
erroneous. In your case, remember
>STRING   (AM.PM) (A3).
>>Error # 4293 in column 10.  Text: (
>>The variable list is empty. This command not executed.

So, variable "AM.PM" is not declared, and is not a string variable.
You can assign a value to a non-existent numeric variable, and SPSS
will create the variable; but, not to a string variable.

It doesn't take much, does it? Try that change, and see how it goes.

-Best of luck,
  Richard

=====================
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