manipulate dates

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

manipulate dates

DeMichele, Matthew
I have a data set with birth dates arranged as 8 digit string variables
with two leading zeros. For instance, 00196011 refers to someone born
November 1960 (the days are left out for privacy reasons). Does anyone
have suggestions for code to convert these string variables to date
format using the 15th for each day? Thank you in advance for any
assistance.

Best regards,
Matthew

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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
Reply | Threaded
Open this post in threaded view
|

Re: manipulate dates

Jon K Peck
data list free/date(a8).
begin data
00196011
end data

compute spssdate = date.mdy(
    numeric(char.substr(date, 7,2), f2.0),
    15,
    numeric(char.substr(date,3,4), f4.0)
).
format spssdate(adate10).


Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
phone: 720-342-5621




From:        "DeMichele, Matthew" <[hidden email]>
To:        [hidden email],
Date:        01/06/2014 09:12 AM
Subject:        [SPSSX-L] manipulate dates
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




I have a data set with birth dates arranged as 8 digit string variables
with two leading zeros. For instance, 00196011 refers to someone born
November 1960 (the days are left out for privacy reasons). Does anyone
have suggestions for code to convert these string variables to date
format using the 15th for each day? Thank you in advance for any
assistance.

Best regards,
Matthew

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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


Reply | Threaded
Open this post in threaded view
|

Re: manipulate dates

Bruce Weaver
Administrator
In reply to this post by DeMichele, Matthew
Replace datestr below with the name of your string variable.

COMPUTE #y = number(char.substr(datestr,3,4),f4).
COMPUTE #m = number(char.substr(datestr,7,2),f2).
COMPUTE DateVar = date.dmy(15,#m,#y).
FORMATS DateVar(date11).

Here is output from a two-line data set I used to test:

datestr      DateVar
 
00196011 15-NOV-1960
00196508 15-AUG-1965


DeMichele, Matthew wrote
I have a data set with birth dates arranged as 8 digit string variables
with two leading zeros. For instance, 00196011 refers to someone born
November 1960 (the days are left out for privacy reasons). Does anyone
have suggestions for code to convert these string variables to date
format using the 15th for each day? Thank you in advance for any
assistance.

Best regards,
Matthew

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: manipulate dates

David Marso
Administrator
Here is another approach using ALTER TYPE.

ALTER TYPE datestr (A10).
COMPUTE datestr=CONCAT(CHAR.SUBSTR(datestr,7,2),"/15/",CHAR.SUBSTR(datestr,3,4)).
ALTER TYPE datestr (ADATE).

You could also use:
COMPUTE numDate=NUMBER(CONCAT(CHAR.SUBSTR(datestr,7,2),"/15/",CHAR.SUBSTR(datestr,3,4)),ADATE).
FORMATS numDate (ADATE).

Bruce Weaver wrote
Replace datestr below with the name of your string variable.

COMPUTE #y = number(char.substr(datestr,3,4),f4).
COMPUTE #m = number(char.substr(datestr,7,2),f2).
COMPUTE DateVar = date.dmy(15,#m,#y).
FORMATS DateVar(date11).

Here is output from a two-line data set I used to test:

datestr      DateVar
 
00196011 15-NOV-1960
00196508 15-AUG-1965


DeMichele, Matthew wrote
I have a data set with birth dates arranged as 8 digit string variables
with two leading zeros. For instance, 00196011 refers to someone born
November 1960 (the days are left out for privacy reasons). Does anyone
have suggestions for code to convert these string variables to date
format using the 15th for each day? Thank you in advance for any
assistance.

Best regards,
Matthew

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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
Bruce Weaver wrote
Replace datestr below with the name of your string variable.

COMPUTE #y = number(char.substr(datestr,3,4),f4).
COMPUTE #m = number(char.substr(datestr,7,2),f2).
COMPUTE DateVar = date.dmy(15,#m,#y).
FORMATS DateVar(date11).

Here is output from a two-line data set I used to test:

datestr      DateVar
 
00196011 15-NOV-1960
00196508 15-AUG-1965


DeMichele, Matthew wrote
I have a data set with birth dates arranged as 8 digit string variables
with two leading zeros. For instance, 00196011 refers to someone born
November 1960 (the days are left out for privacy reasons). Does anyone
have suggestions for code to convert these string variables to date
format using the 15th for each day? Thank you in advance for any
assistance.

Best regards,
Matthew

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (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
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"