Date

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

Date

Stella Vasquez

Hello SPSS Users,

 

I need to change my Date of Birth variable (adate10) to a number variable with no slashes, dashes or spaces. Can someone please help me out?

 

Thanks.

 

Stella Vasquez



**The information contained in this communication is privileged and confidential and is intended solely for the individual[s] and/or entities named herein. This information is not to be disseminated. If you have received this message in error, please reply to the sender and notify the sender of the error and then permanently delete the message and sent item. Thank you.**
Reply | Threaded
Open this post in threaded view
|

Re: Date

Maguin, Eugene
Stella,
 
If you are reading the data in from a text file, you can specify a format of Adate10 or, maybe in your case, Date11 or Edate11 depending on the separator character used. If you've already read the data in or have in an spss data file, you can use the Number function with a date format to convert the values.
 
compute newdate=number(olddate,adate10).
 
But, if the separator character is non standard, maybe like 27/11/2003 (dd/mm/yyyy), you can use the replace function to change '/' to something spss will recognize with a international/european date format and then use the number function.
 
Or, you can use the substring, number, date.mdy functions to tear the string value apart, convert the parts to numeric and reassemble it. An Interesting exercise.
 
Gene Maguin
 


From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Stella Vasquez
Sent: Monday, June 20, 2011 3:51 PM
To: [hidden email]
Subject: Date

Hello SPSS Users,

 

I need to change my Date of Birth variable (adate10) to a number variable with no slashes, dashes or spaces. Can someone please help me out?

 

Thanks.

 

Stella Vasquez



**The information contained in this communication is privileged and confidential and is intended solely for the individual[s] and/or entities named herein. This information is not to be disseminated. If you have received this message in error, please reply to the sender and notify the sender of the error and then permanently delete the message and sent item. Thank you.**
Reply | Threaded
Open this post in threaded view
|

Re: Date

John Fiedler

Hi Stella!

 

To “tear the string apart,” as Gene suggests, can be done something like the syntax below. The string I was giving looked like this:

2011-05-10 00:49:51

 

COMPUTE year  = NUMBER(SUBSTR(date_time,1,4),F4.0).

COMPUTE month = NUMBER(SUBSTR(date_time,6,2),F2.0).

COMPUTE day   = NUMBER(SUBSTR(date_time,9,2),F2.0).

 

COMPUTE hour  = NUMBER(SUBSTR(date_time,12,2),F2.0).

COMPUTE min   = NUMBER(SUBSTR(date_time,15,2),F2.0).

COMPUTE sec   = NUMBER(SUBSTR(date_time,18,2),F2.0).

 

COMPUTE date = DATE.mdy(month,day,year).

COMPUTE time = TIME.HMS(hour,min,sec).

 

COMPUTE date.time = date + time.

FORMAT date.time(DATETIME20).

 

JOHN

 

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Gene Maguin
Sent: Monday, June 20, 2011 2:24 PM
To: [hidden email]
Subject: Re: Date

 

Stella,

 

If you are reading the data in from a text file, you can specify a format of Adate10 or, maybe in your case, Date11 or Edate11 depending on the separator character used. If you've already read the data in or have in an spss data file, you can use the Number function with a date format to convert the values.

 

compute newdate=number(olddate,adate10).

 

But, if the separator character is non standard, maybe like 27/11/2003 (dd/mm/yyyy), you can use the replace function to change '/' to something spss will recognize with a international/european date format and then use the number function.

 

Or, you can use the substring, number, date.mdy functions to tear the string value apart, convert the parts to numeric and reassemble it. An Interesting exercise.

 

Gene Maguin

 

 


From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Stella Vasquez
Sent: Monday, June 20, 2011 3:51 PM
To: [hidden email]
Subject: Date

Hello SPSS Users,

 

I need to change my Date of Birth variable (adate10) to a number variable with no slashes, dashes or spaces. Can someone please help me out?

 

Thanks.

 

Stella Vasquez

 


**The information contained in this communication is privileged and confidential and is intended solely for the individual[s] and/or entities named herein. This information is not to be disseminated. If you have received this message in error, please reply to the sender and notify the sender of the error and then permanently delete the message and sent item. Thank you.**

Reply | Threaded
Open this post in threaded view
|

Re: Date

Rick Oliver-3
In reply to this post by Stella Vasquez
compute #month=xdate.month(bdate).
compute #day=xdate.mday(bdate).
compute #year=xdate.year(bdate).
compute newdate=#month*1000000+#day*10000+#year.
formats newdate(n8).

The n format retains leading zeroes for single digit months. The order of the values in this example preserves the adate order of values, but you could just as easily change the order to d/m/y or y/m/d.



From:        Stella Vasquez <[hidden email]>
To:        [hidden email]
Date:        06/20/2011 02:54 PM
Subject:        Date
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hello SPSS Users,
 
I need to change my Date of Birth variable (adate10) to a number variable with no slashes, dashes or spaces. Can someone please help me out?
 
Thanks.
 
Stella Vasquez



**The information contained in this communication is privileged and confidential and is intended solely for the individual[s] and/or entities named herein. This information is not to be disseminated. If you have received this message in error, please reply to the sender and notify the sender of the error and then permanently delete the message and sent item. Thank you.**