Part of a data to a date format - how to?

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

Part of a data to a date format - how to?

Mark Webb-5
String field Month has entries like "May".
I would like to use syntax to convert this to date format dd.mm.yyyy like 01.05.2015
Have tried the data & time wizards with no success. Also tried simple syntax like below with no success.
Hints please on how solve this.

I pre-made the Month2 field with this date format dd.mm.yyyy

if Month= "May" Month2 = "01.05.2015".
exe.

-- 
Mark Webb

Line +27 (21) 786 4379
Cell +27 (72) 199 1000 [Poor reception]
Fax  +27 (86) 260 1946 

Skype       tomarkwebb 
Email       [hidden email] 
===================== 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: Part of a data to a date format - how to?

J. Salford
Try:

data list list / month (a9).
begin data
January
February
March
April
May
June
July
August
September
October
November
December
end data.

Do repeat x = 'january' 'february' 'march' 'april' 'may' 'june' 'july' 'august' 'september' 'october' 'november' 'december' / y = 1 to 12.
if (lower(month) eq x) month2 = date.dmy(1,y,2015).
end repeat.
formats month2 (edate10).
exe.

Reply | Threaded
Open this post in threaded view
|

Re: Part of a data to a date format - how to?

John F Hall
In reply to this post by Mark Webb-5

Mark

 

Not sure what your data for month look like, but you could use AUTORECODE to turn month into a numeric variable with values 1 – 12 (unless you have some varied entries for month): recodes will be in alphabetical, not annual order

(1=April  2= December 3=February, 4=March . . .)  You can then use RECODE to get them in the right order and label the values.

 

AUTORECODE variables = month /into month2 /blank = missing.

RECODE month2 (1=4)(2=12)(3=5)  . . .

FREQUENCIES month2.

 

VALUE LABELS month2

1 ‘January’ 2 ‘February’ . . .  12’December’ 13 ‘Blank’

 

Another way would be to use RECODE alone, but this depends on how the data are actually entered.

 

RECODE Month

               (‘January’ = 1) … (‘May’ = 5) …(‘December’ = 12)

               into month2.

Format month2 (f2.0)

VALUE LABELS month2

1 ‘January’ 2 ‘February’ . . .  12’December’.

 

Do you have separate dates within months?  If all you want is month and all the months are in 2015, you could try (no idea if this will work)

 

1:            Open the Data Editor in Data View

2:            Click on the column header for month2 to highlight the whole column

3:            Use [CTRL]+H to change values

1 to Jan 2015,

2 to Feb 2015 etc.

 

There’s nothing in the manual to show how to recode to a date format, but someone else on the list may come up with a solution.

 

John F Hall (Mr)

[Retired academic survey researcher]

 

Email:   [hidden email] 

Website: www.surveyresearch.weebly.com

SPSS start page:  www.surveyresearch.weebly.com/1-survey-analysis-workshop

 

 

 

 

From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Mark Webb
Sent: 23 May 2015 08:20
To: [hidden email]
Subject: Part of a data to a date format - how to?

 

String field Month has entries like "May".
I would like to use syntax to convert this to date format dd.mm.yyyy like 01.05.2015
Have tried the data & time wizards with no success. Also tried simple syntax like below with no success.
Hints please on how solve this.

I pre-made the Month2 field with this date format dd.mm.yyyy

if Month= "May" Month2 = "01.05.2015".
exe.


-- 
Mark Webb
 
Line +27 (21) 786 4379
Cell +27 (72) 199 1000 [Poor reception]
Fax  +27 (86) 260 1946 
 
Skype       tomarkwebb 
Email       [hidden email] 

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