Can I use ALTER TYPE for F8 to SDATE10 ?

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

Can I use ALTER TYPE for F8 to SDATE10 ?

Ruben Geert van den Berg
Dear all,

I've a numeric variable that I'd like to convert to a date. Its format is yyyymmdd (F8). For example

data list free/date(f8)time(f6).
begin data
20111030        232005
end data.

I thought I could convert it to a proper date using

alter type date(sdate10).

but that results in June 3rd, 1583, which is the exact same outcome as using

format date(sdate10).

instead of an ALTER TYPE command. So no real conversion took place, just a change in representation. Can't I use ALTER TYPE at all in this case? I know I can use

compute newdate=date.dmy(num(subs(str(date,f8),7,2),f2),num(subs(str(date,f8),5,2),f2),num(subs(str(date,f8),1,4),f4)).

but I thought that was deprecated after ALTER TYPE was introduced.

TIA!
Reply | Threaded
Open this post in threaded view
|

Re: Can I use ALTER TYPE for F8 to SDATE10 ?

Jon K Peck
ALTER TYPE could not do the conversion you want, because the actual input date format is unknown.  You want sdate10 as the result, but the input is just an F formatted value, so the actual value would have to already be an SPSS date value, which it is not in this case.

Date values are a numeric fundamental type, and the format command is just a display specification.


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




From:        Ruben Geert van den Berg <[hidden email]>
To:        [hidden email],
Date:        05/15/2013 11:26 PM
Subject:        [SPSSX-L] Can I use ALTER TYPE for F8 to SDATE10 ?
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Dear all,

I've a numeric variable that I'd like to convert to a date. Its format is
yyyymmdd (F8). For example

data list free/date(f8)time(f6).
begin data
20111030        232005
end data.

I thought I could convert it to a proper date using

alter type date(sdate10).

but that results in June 3rd, 1583, which is the exact same outcome as using

format date(sdate10).

instead of an ALTER TYPE command. So no real conversion took place, just a
change in representation. Can't I use ALTER TYPE at all in this case? I know
I can use

compute
newdate=date.dmy(num(subs(str(date,f8),7,2),f2),num(subs(str(date,f8),5,2),f2),num(subs(str(date,f8),1,4),f4)).

but I thought that was deprecated after ALTER TYPE was introduced.

TIA!



--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Can-I-use-ALTER-TYPE-for-F8-to-SDATE10-tp5720276.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


Reply | Threaded
Open this post in threaded view
|

Re: Can I use ALTER TYPE for F8 to SDATE10 ?

ViAnn Beadle
In reply to this post by Ruben Geert van den Berg
Too little time to fire up version 21 but I thought if you read a date in as
a date you can just give it a different format via the format command? IIRC,
ALTER TYPE is used to quickly convert strings to numbers and vice versa.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Ruben Geert van den Berg
Sent: Wednesday, May 15, 2013 11:18 PM
To: [hidden email]
Subject: Can I use ALTER TYPE for F8 to SDATE10 ?

Dear all,

I've a numeric variable that I'd like to convert to a date. Its format is
yyyymmdd (F8). For example

data list free/date(f8)time(f6).
begin data
20111030        232005
end data.

I thought I could convert it to a proper date using

alter type date(sdate10).

but that results in June 3rd, 1583, which is the exact same outcome as using

format date(sdate10).

instead of an ALTER TYPE command. So no real conversion took place, just a
change in representation. Can't I use ALTER TYPE at all in this case? I know
I can use

compute
newdate=date.dmy(num(subs(str(date,f8),7,2),f2),num(subs(str(date,f8),5,2),f
2),num(subs(str(date,f8),1,4),f4)).

but I thought that was deprecated after ALTER TYPE was introduced.

TIA!



--
View this message in context:
http://spssx-discussion.1045642.n5.nabble.com/Can-I-use-ALTER-TYPE-for-F8-to
-SDATE10-tp5720276.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: Can I use ALTER TYPE for F8 to SDATE10 ?

Art Kendall
In reply to this post by Ruben Geert van den Berg
Dates are represented as seconds since the start of the Gregorian calendar.
I use low number such as 1 day (86400) as a missing data value.

I recently asked for newer ways to go from A6 to a date.  see the archives for
 "6 character number to SPSS date"

The example syntax below show the some data formatting.

new file.
data list free/mydate(f8).
begin data
20111030
86400
1
end data.
alter type mydate(sdate10).
list.
data list free /actualdate (sdate10).
begin data
2011/10/30
2011/10/31
end data.
alter type actualdate (adate11).
list.
alter type actualdate (date11).
list.
alter type actualdate (f16).
list.

Art Kendall
Social Research Consultants
On 5/16/2013 1:17 AM, Ruben Geert van den Berg [via SPSSX Discussion] wrote:
Dear all,

I've a numeric variable that I'd like to convert to a date. Its format is yyyymmdd (F8). For example

data list free/date(f8)time(f6).
begin data
20111030        232005
end data.

I thought I could convert it to a proper date using

alter type date(sdate10).

but that results in June 3rd, 1583, which is the exact same outcome as using

format date(sdate10).

instead of an ALTER TYPE command. So no real conversion took place, just a change in representation. Can't I use ALTER TYPE at all in this case? I know I can use

compute newdate=date.dmy(num(subs(str(date,f8),7,2),f2),num(subs(str(date,f8),5,2),f2),num(subs(str(date,f8),1,4),f4)).

but I thought that was deprecated after ALTER TYPE was introduced.

TIA!


If you reply to this email, your message will be added to the discussion below:
http://spssx-discussion.1045642.n5.nabble.com/Can-I-use-ALTER-TYPE-for-F8-to-SDATE10-tp5720276.html
To start a new topic under SPSSX Discussion, email [hidden email]
To unsubscribe from SPSSX Discussion, click here.
NAML

Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Can I use ALTER TYPE for F8 to SDATE10 ?

David Marso
Administrator
In reply to this post by Ruben Geert van den Berg
Need to massage the input just a bit.
DATA LIST free/date(f8)time(f6).
BEGIN DATA
20111030        232005
END DATA.
ALTER TYPE  date (A10).
COMPUTE date=CONCAT(CHAR.SUBSTR(date,3,4),
                                     "-",
                                     CHAR.SUBSTR(DATE,7,2),
                                     "-",
                                     CHAR.SUBSTR(date,9)).
ALTER TYPE date(sdate10).
LIST.

      date   time

2011/10/30 232005


Number of cases read:  1    Number of cases listed:  1

Ruben Geert van den Berg wrote
Dear all,

I've a numeric variable that I'd like to convert to a date. Its format is yyyymmdd (F8). For example

data list free/date(f8)time(f6).
begin data
20111030        232005
end data.

I thought I could convert it to a proper date using

alter type date(sdate10).

but that results in June 3rd, 1583, which is the exact same outcome as using

format date(sdate10).

instead of an ALTER TYPE command. So no real conversion took place, just a change in representation. Can't I use ALTER TYPE at all in this case? I know I can use

compute newdate=date.dmy(num(subs(str(date,f8),7,2),f2),num(subs(str(date,f8),5,2),f2),num(subs(str(date,f8),1,4),f4)).

but I thought that was deprecated after ALTER TYPE was introduced.

TIA!
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?"
Reply | Threaded
Open this post in threaded view
|

Re: Can I use ALTER TYPE for F8 to SDATE10 ?

Ruben Geert van den Berg
OK, no shortcut here so far...

I was expecting "sdate10" to do the ALTER TYPE trick. As in "sdate10 means yyyy-mm-dd so then the first four digits must be interpreted as the year ... " and so on. Similarly to converting a string date ("2011-04-13").

@David: yeah, better indeed.