Re: SPSS date transformation help

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

Re: SPSS date transformation help

John F Hall
Jazgul
 
Bit outside my field I'm afraid, and it will take me too long to find out.  Someone on the list will know.  ViAnn Beadle, Jon Peck and  Bruce Weaver usually give knowledgable replies.  There was something a while back on converting seconds to years or vice versa, something like that, but I've deleted my copies 
 
John
----- Original Message -----
Sent: Thursday, October 08, 2009 8:55 AM
Subject: SPSS date transfromation help

Hello John,

Could you kindly help me wit hthe following task.

I have a date in the following format:
   05-OCT-2009 09:12:28
   05-OCT-2009 11:18:12
   05-OCT-2009 12:39:45
   05-OCT-2009 15:09:49
   05-OCT-2009 15:45:22
   05-OCT-2009 19:26:40
   05-OCT-2009 20:14:04

What I need is this

 051009 
 051009 
 051009 
 051009 
 051009 
 051009 
 051009 
I come up with the script:

STRING rdate (A6).
compute rdate= concat (string (xdate.mday (intend), f2.0), lpad (ltrim (string (xdate.month (intend), f2.0)), 2, "0"), substr (string (xdate.year (intend), f4.0), 3, 2)).
EXE.

But then I get just:
 51009 
 51009 
 51009 
 51009 
 51009 
 51009 
 51009 

How can I add 0s in the day? So that it is 6 digit?


Thank you in advance,

Jazgul
Reply | Threaded
Open this post in threaded view
|

Re: SPSS date transformation help

Jarrod Teo-2
Hello Jazgul,

My data is almost the same as yours but I figure that you might want to include data that has the following in red.

   05-OCT-2009 09:12:28
   05-OCT-2009 11:18:12
   05-OCT-2009 12:39:45
   05-OCT-2009 15:09:49
   05-OCT-2009 15:45:22
   05-OCT-2009 19:26:40
   05-OCT-2009 20:14:04
   10-OCT-2009 20:14:04

This is because you will need to consider the fact that you might have dates that have 10-31 day.

05-OCT-2009 20:14:04 entries are fine because you will get 051009 but it cause a problem if you will to add a '0' in front of entries like 10-OCT-2009 20:14:04 which will give you 0101009 if your final date variable is of width a8.

So maybe you can try this. If you still have problem understanding my syntax, do tell me.

string daydraft month (a2) year (a4).
compute daydraft=string(xdate.mday(date),f2).
compute month=string(xdate.month(date),f2).
compute year=string(xdate.year(date),f4).
freq daydraft to year.


compute daydraft2=xdate.mday(date).
freq daydraft2.

string day (a2).
do if (daydraft2 lt 10).
compute day=replace(daydraft,' ', '0').
else if (daydraft2 ge 10).
compute day=daydraft.
end if.
freq day.

string datefinal (a6).
compute datefinal=concat(da! y,month,substring(year,3,2)).
freq datefinal.

Regards
Dorraj


Date: Thu, 8 Oct 2009 09:47:40 +0200
From: [hidden email]
Subject: Re: SPSS date transformation help
To: [hidden email]

Jazgul
 
Bit outside my field I'm afraid, and it will take me too long to find out.  Someone on the list will know.  ViAnn Beadle, Jon Peck and  Bruce Weaver usually give knowledgable replies.  There was something a while back on converting seconds to years or vice versa, something like that, but I've deleted my copies 
 
John
----- Original Message -----
Sent: Thursday, October 08, 2009 8:55 AM
Subject: SPSS date transfromation help

Hello John,

Could you kindly help me wit hthe following task.

I have a date in the following format:
   05-OCT-2009 09:12:28
   05-OCT-2009 11:18:12
   05-OCT-2009 12:39:45
   05-OCT-2009 15:09:49
   05-OCT-2009 15:45:22
   05-OCT-2009 19:26:40
   05-OCT-2009 20:14:04

What I need is this

 051009 
 051009 
 051009 
 051009 
 051009 
 051009 
 051009 
I come up with the script:

STRING rdate (A6).
compute rdate= concat (string (xdate.mday (intend), f2.0), lpad (ltrim (string (xdate.month (intend), f2.0)), 2, "0"), substr (string (xdate.year (intend), f4.0), 3, 2)).
EXE.

But then I get just:
 51009 
 51009 
 51009 
 51009 
 51009 
 51009 
 51009 

How can I add 0s in the day? So that it is 6 digit?


Thank you in advance,

Jazgul


Windows Live: Make it easier for your friends to see what you’re up to on Facebook.
Reply | Threaded
Open this post in threaded view
|

Re: SPSS date transformation help

John F Hall
This came to me.  Did you get it as well?  Not sure who SPSS Syntax help is, unless it's the same as the listserver.
----- Original Message -----
Sent: Thursday, October 08, 2009 11:24 AM
Subject: RE: SPSS date transformation help

Hello Jazgul,

My data is almost the same as yours but I figure that you might want to include data that has the following in red.

   05-OCT-2009 09:12:28
   05-OCT-2009 11:18:12
   05-OCT-2009 12:39:45
   05-OCT-2009 15:09:49
   05-OCT-2009 15:45:22
   05-OCT-2009 19:26:40
   05-OCT-2009 20:14:04
   10-OCT-2009 20:14:04

This is because you will need to consider the fact that you might have dates that have 10-31 day.

05-OCT-2009 20:14:04 entries are fine because you will get 051009 but it cause a problem if you will to add a '0' in front of entries like 10-OCT-2009 20:14:04 which will give you 0101009 if your final date variable is of width a8.

So maybe you can try this. If you still have problem understanding my syntax, do tell me.

string daydraft month (a2) year (a4).
compute daydraft=string(xdate.mday(date),f2).
compute month=string(xdate.month(date),f2).
compute year=string(xdate.year(date),f4).
freq daydraft to year.


compute daydraft2=xdate.mday(date).
freq daydraft2.

string day (a2).
do if (daydraft2 lt 10).
compute day=replace(daydraft,' ', '0').
else if (daydraft2 ge 10).
compute day=daydraft.
end if.
freq day.

string datefinal (a6).
compute datefinal=concat(day ,month,substring(year,3,2)).
freq datefinal.

Regards
Dorraj


Date: Thu, 8 Oct 2009 09:47:40 +0200
From: [hidden email]
Subject: Re: SPSS date transformation help
To: [hidden email]

Jazgul
 
Bit outside my field I'm afraid, and it will take me too long to find out.  Someone on the list will know.  ViAnn Beadle, Jon Peck and  Bruce Weaver usually give knowledgable replies.  There was something a while back on converting seconds to years or vice versa, something like that, but I've deleted my copies 
 
John
----- Original Message -----
Sent: Thursday, October 08, 2009 8:55 AM
Subject: SPSS date transfromation help

Hello John,

Could you kindly help me wit hthe following task.

I have a date in the following format:
   05-OCT-2009 09:12:28
   05-OCT-2009 11:18:12
   05-OCT-2009 12:39:45
   05-OCT-2009 15:09:49
   05-OCT-2009 15:45:22
   05-OCT-2009 19:26:40
   05-OCT-2009 20:14:04

What I need is this

 051009 
 051009 
 051009 
 051009 
 051009 
 051009 
 051009 
I come up with the script:

STRING rdate (A6).
compute rdate= concat (string (xdate.mday (intend), f2.0), lpad (ltrim (string (xdate.month (intend), f2.0)), 2, "0"), substr (string (xdate.year (intend), f4.0), 3, 2)).
EXE.

But then I get just:
 51009 
 51009 
 51009 
 51009 
 51009 
 51009 
 51009 

How can I add 0s in the day? So that it is 6 digit?


Thank you in advance,

Jazgul


Windows Live: Make it easier for your friends to see what you’re up to on Facebook.
Reply | Threaded
Open this post in threaded view
|

Re: SPSS date transformation help

wsu_wright
In reply to this post by John F Hall
If it doesn't have to be a string you could convert it to a numeric with
leading zeros.

ALTER TYPE rdate (N6.0).



David


On Thu, Oct 8, 2009 at 4:24 AM, DorraJ Oet wrote:

> Hello Jazgul,
>
> My data is almost the same as yours but I figure that you might want
> to include data that has the following in red.
>
>
>   05-OCT-2009 09:12:28
>    05-OCT-2009 11:18:12
>
>   05-OCT-2009 12:39:45
>    05-OCT-2009 15:09:49
>
>   05-OCT-2009 15:45:22
>    05-OCT-2009 19:26:40
>
>   05-OCT-2009 20:14:04
>    10-OCT-2009 20:14:04
>
>
> This is because you will need to consider the fact that you might have
> dates that have 10-31 day.
>
> 05-OCT-2009 20:14:04 entries are fine because you will get 051009 but
> it cause a problem if you will to add a '0' in front of entries like
> 10-OCT-2009 20:14:04 which will give you 0101009 if your final date
> variable is of width a8.
>
> So maybe you can try this. If you still have problem understanding my
> syntax, do tell me.
>
> string daydraft month (a2) year (a4).
> compute daydraft=string(xdate.mday(date),f2).
> compute month=string(xdate.month(date),f2).
> compute year=string(xdate.year(date),f4).
> freq daydraft to year.
>
>
> compute daydraft2=xdate.mday(date).
> freq daydraft2.
>
> string day (a2).
> do if (daydraft2 lt 10).
> compute day=replace(daydraft,' ', '0').
> else if (daydraft2 ge 10).
> compute day=daydraft.
> end if.
> freq day.
>
> string datefinal (a6).
> compute datefinal=concat(day,month,substring(year,3,2)).
> freq datefinal.
>
> Regards
> Dorraj
>
> Date: Thu, 8 Oct 2009 09:47:40 +0200
> From: [hidden email]
> Subject: Re: SPSS date transformation help
> To: [hidden email]
>
>
>
>
>
>
>
>
>
>
> Jazgul
>
> Bit outside my field I'm afraid, and it will take
> me too long to find out.  Someone on the list will know.  ViAnn
> Beadle, Jon Peck and  Bruce Weaver usually give knowledgable
> replies.  There was something a while back on converting seconds to
> years
> or vice versa, something like that, but I've deleted my
> copies
>
> John
>
>   ----- Original Message -----
>   From:
>   Jazgul
>   Ismailova
>   To: [hidden email]
>   Sent: Thursday, October 08, 2009 8:55
>   AM
>   Subject: SPSS date transfromation
>   help
>
> Hello John,
>
> Could you kindly help me wit hthe following
>   task.
>
> I have a date in the following format:
>
>   05-OCT-2009 09:12:28
>    05-OCT-2009 11:18:12
>
>   05-OCT-2009 12:39:45
>    05-OCT-2009 15:09:49
>
>   05-OCT-2009 15:45:22
>    05-OCT-2009 19:26:40
>
>   05-OCT-2009 20:14:04
>
> What I need is this
>
>  051009
>
>  051009
>  051009
>  051009
>
>  051009
>  051009
>  051009
> I
>   come up with the script:
>
> STRING rdate (A6).
> compute rdate= concat
>   (string (xdate.mday (intend), f2.0), lpad (ltrim (string
> (xdate.month
>   (intend), f2.0)), 2, "0"), substr (string (xdate.year (intend),
> f4.0), 3,
>   2)).
> EXE.
>
> But then I get just:
>  51009
>
>  51009
>  51009
>  51009
>
>  51009
>  51009
>  51009
>
> How
>   can I add 0s in the day? So that it is 6 digit?
>
>
> Thank you in
>   advance,
>
> Jazgul
>
> _________________________________________________________________
> Windows Live: Make it easier for your friends to see what you’re up to
> on Facebook.
>
> http://www.microsoft.com/windows/windowslive/see-it-in-action/social-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-sg:SI_SB_2:092009

=====================
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: SPSS date transformation help

Bruce Weaver
Administrator
In reply to this post by John F Hall
John F Hall-2 wrote
Jazgul

Bit outside my field I'm afraid, and it will take me too long to find out.  Someone on the list will know.  ViAnn Beadle, Jon Peck and  Bruce Weaver usually give knowledgable replies.  There was something a while back on converting seconds to years or vice versa, something like that, but I've deleted my copies

John
  ----- Original Message -----
  From: Jazgul Ismailova
  To: johnfhall@orange.fr
  Sent: Thursday, October 08, 2009 8:55 AM
  Subject: SPSS date transfromation help


  Hello John,

  Could you kindly help me wit hthe following task.

  I have a date in the following format:
     05-OCT-2009 09:12:28
     05-OCT-2009 11:18:12
     05-OCT-2009 12:39:45
     05-OCT-2009 15:09:49
     05-OCT-2009 15:45:22
     05-OCT-2009 19:26:40
     05-OCT-2009 20:14:04

  What I need is this

   051009  
   051009  
   051009  
   051009  
   051009  
   051009  
   051009  
  I come up with the script:

  STRING rdate (A6).
  compute rdate= concat (string (xdate.mday (intend), f2.0), lpad (ltrim (string (xdate.month (intend), f2.0)), 2, "0"), substr (string (xdate.year (intend), f4.0), 3, 2)).
  EXE.

  But then I get just:
   51009  
   51009  
   51009  
   51009  
   51009  
   51009  
   51009  

  How can I add 0s in the day? So that it is 6 digit?


  Thank you in advance,

  Jazgul
How about this?  DATEVAR refers to your original date-time variable.

format datevar (edate9).
string newdatestr (a8).
compute newdatestr = replace(string(datevar,edate9),".","").
exe.

Formatting as EDATE9 changes the dates to 05.10.09.  The COMPUTE statement converts that date variable to a string, then replaces "." with "".

--
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: SPSS date transformation help

Melissa Ives
In reply to this post by wsu_wright
It seems to me that you could also solve this by changing the format from f2 to n2 like this
(totally NOT tested).  I suspect that with the original syntax you will have the same issue for dates before October. e.g. Sept 5, 2009 would end up as:  5909 instead of 050909

STRING rdate (A6).
compute rdate= concat
   (string (xdate.mday (intend), n2.0), lpad (ltrim (string(xdate.month
   (intend), n2.0)), 2, "0"), substr (string (xdate.year (intend),f4.0),3,2)).


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of David Wright
Sent: Thursday, October 08, 2009 5:41 AM
To: [hidden email]
Subject: Re: [SPSSX-L] SPSS date transformation help

If it doesn't have to be a string you could convert it to a numeric with leading zeros.

ALTER TYPE rdate (N6.0).



David


On Thu, Oct 8, 2009 at 4:24 AM, DorraJ Oet wrote:

> Hello Jazgul,
>
> My data is almost the same as yours but I figure that you might want
> to include data that has the following in red.
>
>
>   05-OCT-2009 09:12:28
>    05-OCT-2009 11:18:12
>
>   05-OCT-2009 12:39:45
>    05-OCT-2009 15:09:49
>
>   05-OCT-2009 15:45:22
>    05-OCT-2009 19:26:40
>
>   05-OCT-2009 20:14:04
>    10-OCT-2009 20:14:04
>
>
> This is because you will need to consider the fact that you might have
> dates that have 10-31 day.
>
> 05-OCT-2009 20:14:04 entries are fine because you will get 051009 but
> it cause a problem if you will to add a '0' in front of entries like
> 10-OCT-2009 20:14:04 which will give you 0101009 if your final date
> variable is of width a8.
>
> So maybe you can try this. If you still have problem understanding my
> syntax, do tell me.
>
> string daydraft month (a2) year (a4).
> compute daydraft=string(xdate.mday(date),f2).
> compute month=string(xdate.month(date),f2).
> compute year=string(xdate.year(date),f4).
> freq daydraft to year.
>
>
> compute daydraft2=xdate.mday(date).
> freq daydraft2.
>
> string day (a2).
> do if (daydraft2 lt 10).
> compute day=replace(daydraft,' ', '0').
> else if (daydraft2 ge 10).
> compute day=daydraft.
> end if.
> freq day.
>
> string datefinal (a6).
> compute datefinal=concat(day,month,substring(year,3,2)).
> freq datefinal.
>
> Regards
> Dorraj
>
> Date: Thu, 8 Oct 2009 09:47:40 +0200
> From: [hidden email]
> Subject: Re: SPSS date transformation help
> To: [hidden email]
>
>
>
>
>
>
>
>
>
>
> Jazgul
>
> Bit outside my field I'm afraid, and it will take me too long to find
> out.  Someone on the list will know.  ViAnn Beadle, Jon Peck and
> Bruce Weaver usually give knowledgable replies.  There was something a
> while back on converting seconds to years or vice versa, something
> like that, but I've deleted my copies
>
> John
>
>   ----- Original Message -----
>   From:
>   Jazgul
>   Ismailova
>   To: [hidden email]
>   Sent: Thursday, October 08, 2009 8:55
>   AM
>   Subject: SPSS date transfromation
>   help
>
> Hello John,
>
> Could you kindly help me wit hthe following
>   task.
>
> I have a date in the following format:
>
>   05-OCT-2009 09:12:28
>    05-OCT-2009 11:18:12
>
>   05-OCT-2009 12:39:45
>    05-OCT-2009 15:09:49
>
>   05-OCT-2009 15:45:22
>    05-OCT-2009 19:26:40
>
>   05-OCT-2009 20:14:04
>
> What I need is this
>
>  051009
>
>  051009
>  051009
>  051009
>
>  051009
>  051009
>  051009
> I
>   come up with the script:
>
> STRING rdate (A6).
> compute rdate= concat
>   (string (xdate.mday (intend), f2.0), lpad (ltrim (string
> (xdate.month
>   (intend), f2.0)), 2, "0"), substr (string (xdate.year (intend),
> f4.0), 3,
>   2)).
> EXE.
>
> But then I get just:
>  51009
>
>  51009
>  51009
>  51009
>
>  51009
>  51009
>  51009
>
> How
>   can I add 0s in the day? So that it is 6 digit?
>
>
> Thank you in
>   advance,
>
> Jazgul
>
> _________________________________________________________________
> Windows Live: Make it easier for your friends to see what you're up to
> on Facebook.
>
> http://www.microsoft.com/windows/windowslive/see-it-in-action/social-n
> etwork-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-sg:SI_SB_2:092009

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

PRIVILEGED AND CONFIDENTIAL INFORMATION
This transmittal and any attachments may contain PRIVILEGED AND
CONFIDENTIAL information and is intended only for the use of the
addressee. If you are not the designated recipient, or an employee
or agent authorized to deliver such transmittals to the designated
recipient, you are hereby notified that any dissemination,
copying or publication of this transmittal is strictly prohibited. If
you have received this transmittal in error, please notify us
immediately by replying to the sender and delete this copy from your
system. You may also call us at (309) 827-6026 for assistance.

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