transforming YYYYMM format into a date in SPSS

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

transforming YYYYMM format into a date in SPSS

vanels
Hi everyone,

I am looking for help!

I have a variable containing a date with the format: YYYYMM. This format is not listed in the conversion wizard of SPSS so I am looking for another way to convert it into a date (any format will do). It seems like SPSS does not like only months and years only, so if it can be converted into DDMMYYYY with all days being the first of that month, it would also be fine.

I am working with SPSS 20.0 and any solutions I have found on the net so far did not work.

Thanks a TON for anyone who can help me out!!

Elsie
 
Reply | Threaded
Open this post in threaded view
|

Re: transforming YYYYMM format into a date in SPSS

Bruce Weaver
Administrator
Is your YYYYMM variable a string?  If so, you could do something like this:

DATA LIST free /datestr (A6).
BEGIN DATA
199010 200109 201201
END DATA.
LIST.

compute #y = number(substr(datestr,1,4),f4).
compute #m = number(substr(datestr,5,2),f2).
compute newdate = DATE.MOYR(#m,#y).
formats newdate(moyr).
list.

OUTPUT:

datestr  newdate
 
199010  OCT 1990
200109  SEP 2001
201201  JAN 2012
 
Number of cases read:  3    Number of cases listed:  3



vanels wrote
Hi everyone,

I am looking for help!

I have a variable containing a date with the format: YYYYMM. This format is not listed in the conversion wizard of SPSS so I am looking for another way to convert it into a date (any format will do). It seems like SPSS does not like only months and years only, so if it can be converted into DDMMYYYY with all days being the first of that month, it would also be fine.

I am working with SPSS 20.0 and any solutions I have found on the net so far did not work.

Thanks a TON for anyone who can help me out!!

Elsie
--
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: transforming YYYYMM format into a date in SPSS

Maguin, Eugene
In reply to this post by vanels
You pick a day. I'll pick the 15th. Let's call the yyyymm string 'x'.

Compute date1=date.mdy(number(substr(x,5,2),f2.0),15, number(substr(x,1,4),f4.0)).

Gene Maguin

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of vanels
Sent: Friday, June 01, 2012 8:35 AM
To: [hidden email]
Subject: transforming YYYYMM format into a date in SPSS

Hi everyone,

I am looking for help!

I have a variable containing a date with the format: YYYYMM. This format is not listed in the conversion wizard of SPSS so I am looking for another way to convert it into a date (any format will do). It seems like SPSS does not like only months and years only, so if it can be converted into DDMMYYYY with all days being the first of that month, it would also be fine.

I am working with SPSS 20.0 and any solutions I have found on the net so far did not work.

Thanks a TON for anyone who can help me out!!

Elsie


--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/transforming-YYYYMM-format-into-a-date-in-SPSS-tp5713463.html
Sent from the SPSSX Discussion mailing list archive at Nabble.com.

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

=====================
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: transforming YYYYMM format into a date in SPSS

David Marso
Administrator
In reply to this post by vanels
If this is a string variable then consider Bruce's and Gene's suggestions.  If Numeric then you will do well to look to the MOD and TRUNC functions to extract the Year and Month components.
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?"