Date: Fri, 28 Aug 1998 13:32:12 -0600
Reply-To: JRLASTRE@MICRONPC.COM
Sender: "SPSSX(r) Discussion" <SPSSX-L@UGA.CC.UGA.EDU>
From: John Rene Lastre <JRLASTRE@MICRONPC.COM>
Subject: Re: string variables and substr function
Dale,
I think the problem is not that the SPSS is not reading "Date" as a STRING
but that you are not defining the new variables "month", "day", and "year"
as a STRING or conversely you are not evaluating the STRING back to a
NUMBER (in which case you need not pre-specify numeric variables). If you
look at what I sent you, you'll see I tried to take this into account.
Specifically:
"
* To read it into a numeric variable and format it.
COMPUTE newdat2=DATE.MDY(NUMBER(SUBSTR(newdat,1,2),f2),
NUMBER(SUBSTR(newdat,3,2),f2),
NUMBER(SUBSTR(newdat,5,2),f2)).
FORMAT newdat2 (ADATE11).
"
Where "newdat" is your "date".
OR the change to your commands:
compute month=number(substr(date,1,2),f2).
compute day =number(substr(date,3,2),f2).
compute year=number(substr(date,5,2),f2).
Not entirely sure these three later statements will work though, as I
believe the STRING format pads "whitespace" at the end of text, not the
beginning. That's why I placed that block of logic to pad the text at the
beginning (with 0's) rather than at the end (with blanks ' '). I'm sure of
my code as I've used it before. But I haven't tested your code with my
additions, so I'm not entirely sure those three lines will work correctly.
(In addition to which I am fairly unfocused today.) :-/
Since I glossed over it in the previous message, I should have pointed out
more forcefully as others on the list have, THAT IF you are unsure as to
the length of the format of the days (i.e. 1 or 2 ) as in dd/m/yy and
dd/mm/yy, as you previously indicated, there will _not_ be a _easy_ or
_complete_ way of doing this. Any dates within the sequence 111xx - 121xx
(excluding 120xx) would be fairly indeterminate. In addition the exception
coding may be fairly extensive for those dates you can format by
induction.
If you wish, we can discuss specifics off or online. I kinda hope to
reduce bandwidth to the list. I'll be at jlastre@concentric.net this
weekend.
----------
From: Dale Glaser[SMTP:dale.glaser@SHARP.COM]
Reply To: Dale Glaser
Sent: Friday, August 28, 1998 12:35 PM
To: SPSSX-L@UGA.CC.UGA.EDU
Subject: string variables and substr function
Hi there...I have attempted to follow some very helpful advice in
converting a numeric date into the objective of an ADATE8 format:
DATE
11996
11295
91295
90495
of which I did find out that the leading zeros were truncated (data was
entered in dBase3)......so in attempting to create a year variable I
employed the following strategy:
...I converted the numeric date into a A6 length string variable (date),
then used the following syntax:
compute month=substr(date,1,2).
compute day =substr(date,3,2).
compute year=substr(date,5,2).
execute.
I get the following error message:
compute month=substr(date,1,2).
>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.
execute.
For some reason, the variable "date", which was indeed converted into a
string variable, is not being recognized as such.....I have tried multiple
strategies, including keeping the variable numeric and attempting to
segment it into month, day, and year accordingly, but it seems that with
SPSS you have to start with a string variable in order to do that....I
thought possibly the problem was the lack of leading zeros, so I attempted
using options such as:
compute newdate=LPAD(date,1,'0').
execute.
but same error message.......hmmmmmm any suggestions........?
take care and thank you!!!
dale glaser