| Author |
Message |
< GenStat ~ Parsing text into dates
|
| AndrewMc |
Posted: Thu Mar 29, 2012 3:33 am |
|
|
|
Joined: 28 Jul 2008
Posts: 41
|
Hi All
I have a text containing some dates:
TEXT DateText; VALUE=!T('16.12.11','5.1.12','11.1.12','20.1.12','24.1.12')
Is there a way in GenStat that I can parse this text into Day, Month, and Year values and store them as variates?
My aim is to create a factor that uses the DateText as labels and the date values as levels.
Cheers, Andrew Mc
Andrew McLachlan
Biometrician
Plant & Food Research
T: +64 6 355 6110
F: +64 6 351 7050
andrew.mclachlan@plantandfood.co.nz
www.plantandfood.co.nz
The New Zealand Institute for Plant & Food Research Limited
Postal Address: Plant & Food Research Palmerston North
Private Bag 11600, Manawatu Mail Centre, Palmerston North, 4442, New Zealand
Physical Address: Plant & Food Research Palmerston North
Batchelar Road, Palmerston North, 4474, New Zealand
The contents of this e-mail are confidential and may be subject to legal privilege.
If you are not the intended recipient you must not use, disseminate, distribute or
reproduce all or any part of this e-mail or attachments. If you have received this
e-mail in error, please notify the sender and delete all material pertaining to this
e-mail. Any opinion or views expressed in this e-mail are those of the individual
sender and may not represent those of The New Zealand Institute for Plant and
Food Research Limited.
Post generated using Mail2Forum (http://www.mail2forum.com) |
_________________ Andrew McLachlan
Plant & Food Research
Palmerston North, New Zealand |
|
| Back to top |
|
| ruth butler |
Posted: Thu Mar 29, 2012 3:48 am |
|
|
|
Joined: 05 Aug 2010
Posts: 14
|
Andrew,
The only way I know is to edit the separators ('.') to be spaces (' '), then read the day, month year into variates, then calculate the date:
EDIT [ch=!t('g/./ /',':')] DateText "TXREPLACE could probably be used for this also"
READ [ch=DateText] day,mon,year
CALC date=date(day; mon; year)
Ruth
Ruth Butler
Biometrician
T: +64 3 325 9501
F: +64 3 325 2074
Ruth.Butler@plantandfood.co.nz
www.plantandfood.co.nz
The New Zealand Institute for Plant and Food Research Limited
Postal Address: Plant & Food Research Lincoln
Private Bag 4704, Christchurch Mail Centre, CHRISTCHURCH 8140
Physical Address: Plant & Food Research Lincoln
Canterbury Agriculture & Science Centre, Gerald St, Lincoln 7608
-----Original Message-----
From: GENSTAT-Request [mailto:GENSTAT@jiscmail.ac.uk] On Behalf Of Andrew McLachlan
Sent: Thursday, 29 March 2012 4:33 p.m.
To: GENSTAT@JISCMAIL.AC.UK
Subject: Parsing text into dates
Hi All
I have a text containing some dates:
TEXT DateText; VALUE=!T('16.12.11','5.1.12','11.1.12','20.1.12','24.1.12')
Is there a way in GenStat that I can parse this text into Day, Month, and Year values and store them as variates?
My aim is to create a factor that uses the DateText as labels and the date values as levels.
Cheers, Andrew Mc
Andrew McLachlan
Biometrician
Plant & Food Research
T: +64 6 355 6110
F: +64 6 351 7050
andrew.mclachlan@plantandfood.co.nz
www.plantandfood.co.nz
The New Zealand Institute for Plant & Food Research Limited
Postal Address: Plant & Food Research Palmerston North
Private Bag 11600, Manawatu Mail Centre, Palmerston North, 4442, New Zealand
Physical Address: Plant & Food Research Palmerston North
Batchelar Road, Palmerston North, 4474, New Zealand
The contents of this e-mail are confidential and may be subject to legal privilege.
If you are not the intended recipient you must not use, disseminate, distribute or
reproduce all or any part of this e-mail or attachments. If you have received this
e-mail in error, please notify the sender and delete all material pertaining to this
e-mail. Any opinion or views expressed in this e-mail are those of the individual
sender and may not represent those of The New Zealand Institute for Plant and
Food Research Limited.
The contents of this e-mail are confidential and may be subject to legal privilege.
If you are not the intended recipient you must not use, disseminate, distribute or
reproduce all or any part of this e-mail or attachments. If you have received this
e-mail in error, please notify the sender and delete all material pertaining to this
e-mail. Any opinion or views expressed in this e-mail are those of the individual
sender and may not represent those of The New Zealand Institute for Plant and
Food Research Limited.
Post generated using Mail2Forum (http://www.mail2forum.com) |
|
|
| Back to top |
|
| david@vsn.co.nz |
Posted: Thu Mar 29, 2012 3:51 am |
|
|
|
Joined: 30 Jul 2009
Posts: 100
|
Dear Andrew,
Quote: I have a text containing some dates:
TEXT DateText; VALUE=!T('16.12.11','5.1.12','11.1.12','20.1.12','24.1.12')
Is there a way in GenStat that I can parse this text into Day, Month, and
Year
Quote: values and store them as variates?
My aim is to create a factor that uses the DateText as labels and the date
values as levels.
READ can read numbers from a text and can have an alternative separator
than the default space, so the following converts the text to day,month &
year.
As year is missing the century (and the default for the DATE function is to
use 1900 if the years are less than 100, you need some logic to make
years < 50 be in the 21st century (i.e. 20XX). As Dates > 50 are probably
in the 19XX range I've added that also to the logic.
TEXT DateText; VALUE=!T('16.12.11','5.1.12','11.1.12','20.1.12','24.1.12')
READ [CH=DateText;PRINT=*;SEPARATOR='.'] Day,Month,Year
VARIATE Date; DREP=9
CALC Year = Year + 1900*(Year < 100) + 100*(Year < 50)
CALC Date = DATE(Day;Month;Year)
PRINT Day,Month,Year,Date; DEC=0
Day Month Year Date
16 12 2011 16-Dec-11
5 1 2012 05-Jan-12
11 1 2012 11-Jan-12
20 1 2012 20-Jan-12
24 1 2012 24-Jan-12
I suppose it would be nice to have a DREP option for READ to allow dates
to be read directly in a specified format.
Regards, David.
______________________________________________
Dr David Baird Statistical Consultant and GenStat Developer
VSN (NZ) Limited (David@VSN.CO.NZ)
8 Mariposa Crescent, Aidanfield, Christchurch 8025, New Zealand
Ph +64 3 3350588 Cell +64 21 1160803
Post generated using Mail2Forum (http://www.mail2forum.com) |
|
|
| Back to top |
|
| AndrewMc |
Posted: Thu Mar 29, 2012 8:41 pm |
|
|
|
Joined: 28 Jul 2008
Posts: 41
|
Thank you both David and Ruth for pointing out the use of the READ directive and for providing such instructive example code.
Cheers, Andrew Mc
Andrew McLachlan
Biometrician
Plant & Food Research
-----Original Message-----
From: GENSTAT-Request [mailto:GENSTAT@jiscmail.ac.uk] On Behalf Of David Baird
Sent: Thursday, 29 March 2012 4:51 p.m.
To: GENSTAT@JISCMAIL.AC.UK
Subject: Re: Parsing text into dates
Dear Andrew,
Quote: I have a text containing some dates:
TEXT DateText; VALUE=!T('16.12.11','5.1.12','11.1.12','20.1.12','24.1.12')
Is there a way in GenStat that I can parse this text into Day, Month, and
Year
Quote: values and store them as variates?
My aim is to create a factor that uses the DateText as labels and the date
values as levels.
READ can read numbers from a text and can have an alternative separator
than the default space, so the following converts the text to day,month &
year.
As year is missing the century (and the default for the DATE function is to
use 1900 if the years are less than 100, you need some logic to make
years < 50 be in the 21st century (i.e. 20XX). As Dates > 50 are probably
in the 19XX range I've added that also to the logic.
TEXT DateText; VALUE=!T('16.12.11','5.1.12','11.1.12','20.1.12','24.1.12')
READ [CH=DateText;PRINT=*;SEPARATOR='.'] Day,Month,Year
VARIATE Date; DREP=9
CALC Year = Year + 1900*(Year < 100) + 100*(Year < 50)
CALC Date = DATE(Day;Month;Year)
PRINT Day,Month,Year,Date; DEC=0
Day Month Year Date
16 12 2011 16-Dec-11
5 1 2012 05-Jan-12
11 1 2012 11-Jan-12
20 1 2012 20-Jan-12
24 1 2012 24-Jan-12
I suppose it would be nice to have a DREP option for READ to allow dates
to be read directly in a specified format.
Regards, David.
______________________________________________
Dr David Baird Statistical Consultant and GenStat Developer
VSN (NZ) Limited (David@VSN.CO.NZ)
8 Mariposa Crescent, Aidanfield, Christchurch 8025, New Zealand
Ph +64 3 3350588 Cell +64 21 1160803
The contents of this e-mail are confidential and may be subject to legal privilege.
If you are not the intended recipient you must not use, disseminate, distribute or
reproduce all or any part of this e-mail or attachments. If you have received this
e-mail in error, please notify the sender and delete all material pertaining to this
e-mail. Any opinion or views expressed in this e-mail are those of the individual
sender and may not represent those of The New Zealand Institute for Plant and
Food Research Limited.
Post generated using Mail2Forum (http://www.mail2forum.com) |
_________________ Andrew McLachlan
Plant & Food Research
Palmerston North, New Zealand |
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You can attach files in this forum You can download files in this forum
|
|
|