Date: Mon, 3 Feb 2003 16:09:06 -0600
Reply-To: "Marks, Jim" <Jim.Marks@lodgenet.com>
Sender: "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From: "Marks, Jim" <Jim.Marks@lodgenet.com>
Subject: Re: Create age format from string format
Content-Type: text/plain; charset="us-ascii"
Hi Karen:
You have the same name for the old (string) variable and the new (date)
variable. Since dob is defined as a string you cannot compute a
numerical value Try this:
DATA LIST FREE /datestr (A10).
BEGIN DATA
2002-10-21
2001-01-30
END DATA.
COMPUTE dob = DATE.MDY(NUMBER(SUBSTR(datestr,6,2),f2.0),
NUMBER(SUBSTR(datestr,9,2),f2.0),NUMBER(SUBSTR(datestr,1,4),f4.0)).
FORMATS dob (ADATE10).
EXE.
Jim Marks
Senior Market Analyst
LodgeNet Entertainment Corporation
-----Original Message-----
From: Karen Widbin [mailto:Karen.Widbin@NYACK.EDU]
Sent: Monday, February 03, 2003 1:06 PM
To: SPSSX-L@LISTSERV.UGA.EDU
Subject: Create age format from string format
I have date of birth information in a a yyyy-mm-dd string variable
called "dob". Since the imports were done some time ago, I am unable to
re-import it.
Please help me convert the original string variable to a date format
using syntax so that I can do multiple time calculations. I have tried
the following, which I found on this listserve:
COMPUTE dob =
DATE.MDY(number(substr(dob,6,2),f2.0),number(substr(dob,9,2),f2.0),numbe
r(substr(dob,1,4),f4.0)).
FORMATS dob (ADATE10).
I get the following error messages: >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.
(- and for the second row of syntax):
>Error # 4836 in column 9. Text: DOB
>Only the formats A and AHEX can be applied to string variables.
>This command not executed.
I have used a work-around to get the data variable I want, as follows:
STRING dob_yr (A4).
COMPUTE dob_yr = SUBSTR(dob,1,4) .
EXECUTE .
STRING dob_mo (A2).
COMPUTE dob_mo = SUBSTR(dob,6,2) .
EXECUTE .
STRING dob_day (A2).
COMPUTE dob_day = SUBSTR(dob,9,2) .
EXECUTE .
STRING slash (A1).
COMPUTE slash = '/' .
EXECUTE .
STRING dob_num (A10).
COMPUTE dob_num = CONCAT(dob_mo,slash,dob_day,slash,dob_yr) .
EXECUTE .
However, my last step after running this syntax needs to be to manually
change the data type from string to a mm-dd-yyyy date variable in the
variable view window) It works, but I would prefer to do this step with
syntax rather than manually, since I have multiple files to work with.
Any kind of a fix that runs completely with syntax would be
appreciated.
Karen Hanson Widbin
Director of Institutional Research
Nyack College | Alliance Theological Seminary
1 S. Blvd.
Nyack, NY 10960-3698
Phone: 845-358-1710, ext. 537
FAX: 845-353-1297
*******************************
This message, including any attachments, contains confidential
information intended for a specific individual and purpose, and is
protected by law. If you are not the intended recipient, please contact
sender immediately by reply e-mail and destroy all copies. You are
hereby notified that any disclosure, copying, or distribution of this
message, or the taking of any action based on it, is strictly
prohibited.
|