LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (January 2008)Back to main SPSSX-L pageJoin or leave SPSSX-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 29 Jan 2008 08:56:32 -0600
Reply-To:     Mark Palmberg <mark-palmberg@uiowa.edu>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Mark Palmberg <mark-palmberg@uiowa.edu>
Subject:      Re: Syntax to transform numeric variable to date variable (x120)
Comments: To: "Oliver, Richard" <roliver@spss.com>
In-Reply-To:  A<E0428445172CB7469BF187FF4D005149079AEA89@CHIEMAIL1.spss.com>
Content-Type: text/plain; charset="us-ascii"

It actually looks like it worked great, Richard. *All* of the original numeric values were in the format yyyymmdd, and a cursory audit of the new values created by the syntax below reveals that everything's where it's supposed to be.

I'm very thankful to you, Melissa, Martin, and Gene. Thanks also to the list for enduring all my traffic yesterday.

Mark

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Oliver, Richard Sent: Monday, January 28, 2008 7:46 PM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Re: Syntax to transform numeric variable to date variable (x120)

Are all of your date values set to system-missing, or just some of them? This syntax will only work with numeric original values of the form yyyymmdd, where all values are exactly 8 digits, all years are 4 digits, all months are 2 digits from 01 to 12, and all days are 2 digits from 01 to 31 (with the month value determining the upper valid day value). In other words, this will work fine for 20070111, which will be converted to 01/11/2007 -- but it won't work for 2007111, which would be tricky to convert with any routine since 111 could be January 11 or November 1.

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Mark Palmberg Sent: Monday, January 28, 2008 4:32 PM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Re: Syntax to transform numeric variable to date variable (x120)

Gene,

I reorganized my file using KEEP (thanks for the help there) so that it now looks like:

ID DATE0001 DATE0002 DATE0003...DATE0120 GFTAMT0001 GFTAMT0002 GFTAMT0003...GFTAMT0120

And then ran this syntax again:

do repeat oldvar=DATE0001 TO DATE0120 /newvar=DATE1 TO DATE120. compute #day=mod(oldvar,100). compute #year=trunc(oldvar/10000). compute #month=trunc(mod(oldvar,10000)/100). compute newvar=date.mdy(#month, #day, #year). end repeat. formats DATE1 TO DATE120 (adate10).

This syntax gave me the following output:

do repeat oldvar=DATE0001 TO DATE0120 /newvar=DATE1 TO DATE120. compute #day=mod(oldvar,100). compute #year=trunc(oldvar/10000). compute #month=trunc(mod(oldvar,10000)/100). compute newvar=date.mdy(#month, #day, #year). end repeat. formats DATE1 TO DATE120 (adate10). EXECUTE. *>Warning # 613 *>One of the arguments to the DATE function is out of range or is not an *>integer. The result has been set to the system-missing value.

So you were right in assuming there are probably other issues involved here.

Thanks!

Mark

-----Original Message----- From: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] On Behalf Of Gene Maguin Sent: Monday, January 28, 2008 12:43 PM To: SPSSX-L@LISTSERV.UGA.EDU Subject: Re: Syntax to transform numeric variable to date variable (x120)

Mark,

I'm not sure if this is the problem but didn't your original file have an order of date1, gift1, date2, gift2, etc?

If so and if you did not change the order before the do repeat then that is a problem because of the way that the 'TO' keyword works. If the variable order in the file is A1 d1 a2 d2 a3 d3 a4 d4, a1 to a4 includes d1 d2 d3 as well as a2 and a3. There may be other problems but this will be a problem.

You can get around this problem by listing all of the variables to be used.

Gene Maguin

===================== To manage your subscription to SPSSX-L, send a message to LISTSERV@LISTSERV.UGA.EDU (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 LISTSERV@LISTSERV.UGA.EDU (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 LISTSERV@LISTSERV.UGA.EDU (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 LISTSERV@LISTSERV.UGA.EDU (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


Back to: Top of message | Previous page | Main SPSSX-L page