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:         Thu, 31 Jan 2008 07:07:18 +0100
Reply-To:     Luca Meyer <lucameyer@vodafone.it>
Sender:       "SPSSX(r) Discussion" <SPSSX-L@LISTSERV.UGA.EDU>
From:         Luca Meyer <lucameyer@vodafone.it>
Subject:      R: date arithmetic
Comments: To: jimjohn <azam.khan@utoronto.ca>
In-Reply-To:  <15186109.post@talk.nabble.com>
Content-Type: text/plain; charset="iso-8859-1"

Hi,

Here is a SPSS 16 tested syntax:

/*** first let's have some test data **/ DATA LIST LIST /DATE1 DATE2 (2N8). BEGIN DATA 20060827 20070717 20080130 20070104 20080130 20071105 END DATA.

/*** i first transform the numeric var into string and then compute date variables from the string ***/ STRING #DATE1S #DATE2S (A8). COMPUTE #DATE1S=STRING(DATE1,N8). COMPUTE #DATE2S=STRING(DATE2,N8). COMPUTE DATE1D = date.dmy(number(substr(ltrim(#DATE1S),7,2),f2.0), number(substr(ltrim(#DATE1S),5,2),f2.0), number(substr(ltrim(#DATE1S),1,4),f4.0)). COMPUTE DATE2D = date.dmy(number(substr(ltrim(#DATE2S),7,2),f2.0), number(substr(ltrim(#DATE2S),5,2),f2.0), number(substr(ltrim(#DATE2S),1,4),f4.0)). VARIABLE LEVEL DATE1D (SCALE). FORMATS DATE1D (ADATE10). VARIABLE WIDTH DATE1D(10). VARIABLE LEVEL DATE2D (SCALE). FORMATS DATE2D (ADATE10). VARIABLE WIDTH DATE2D(10).

/*** now let's compute the difference between the new variables ***/ COMPUTE DIFFM = DATEDIF(DATE1D, DATE2D, "months"). VARIABLE LABEL DIFFM. VARIABLE LEVEL DIFFM (SCALE). FORMATS DIFFM (F5.0). VARIABLE WIDTH DIFFM(5).

/*** and finally select the cases you need ***/ SELECT IF ABS(DIFFM)<8. EXE.

HTH, Luca

Mr. Luca MEYER Market research, data analysis & more www.lucameyer.com - Tel: +39.339.495.00.21

-----Messaggio originale----- Da: SPSSX(r) Discussion [mailto:SPSSX-L@LISTSERV.UGA.EDU] Per conto di jimjohn Inviato: mercoledý 30 gennaio 2008 18.16 A: SPSSX-L@LISTSERV.UGA.EDU Oggetto: date arithmetic

hi guys i have two numeric variables with dates in the following format yyyymmdd, one of them is always greater than equal to the other

i want to get rid of all my records for which there is less than 8 months difference between these two variables.

does anyone know how to do this in spss? i know of a datediff function, but my variable has to be a string for that? is there a way to maybe just convert them to strings and then use datediff? thanks. -- View this message in context: http://www.nabble.com/date-arithmetic-tp15186109p15186109.html Sent from the SPSSX Discussion mailing list archive at Nabble.com.

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

No virus found in this incoming message. Checked by AVG Free Edition. Version: 7.5.516 / Virus Database: 269.19.14/1247 - Release Date: 28/01/2008 10.59

No virus found in this outgoing message. Checked by AVG Free Edition. Version: 7.5.516 / Virus Database: 269.19.14/1247 - Release Date: 28/01/2008 10.59

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