How to truncate a variable in SPSS?

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

How to truncate a variable in SPSS?

jimjohn
I have a date variable (a string) in the following format:
mm/dd/yyyy 0:00:00

I want to get rid of the 0:00:00 at the end of each of my values, because otherwise it doesn't convert to a date format properly. Any suggestions on what function I can use to do this? Thanks so much!
Reply | Threaded
Open this post in threaded view
|

How to open a view in SPSS 15.0

Allen Frommelt
I am trying to open a view in SPSS 15.0 using the query wizard, but I get the following error:
>Warning.  Command name: GET DATA
>SQLExecDirect failed :[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'Dell.dbo.Dell_poptablesw_2004'.
>[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'Dell.dbo.Dell_poptablesw_2005'.
>[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'Dell.dbo.Dell_poptablesw_2006'.
>[Microsoft][ODBC SQL Server Driver][SQL Server]Invalid object name 'Dell.dbo.Dell_poptablesw_2007'.
>[Microsoft][ODBC SQL Server Driver][SQL Server]Could not use view or function 'dbo.vDell_PopTableSW_20080522' because of binding errors.

I have no trouble opening a table from a database, but I'm not sure why there is a problem opening a view.  Any help or suggestions would be greatly appreciated.  Our databases are stored in Microsoft SQL Server environment.

Thanks!

Allen Frommelt

This email and all attachments are confidential and intended solely
for the use of the individual or entity to which they are addressed.
If you have received this email in error please notify the sender
by replying to this message. If you are not the intended recipient,
please delete this message and all attachments immediately.  Do not
copy, disclose, use or act upon the information contained. Please
note that any views or opinions presented in this email are solely
those of the author and do not necessarily represent those of the
company. Finally, the recipient should check this email and any
attachments for the presence of viruses. While every attempt is made
to verify that the contents are safe, the company accepts no liability
for any damage caused by any virus transmitted by this 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: How to truncate a variable in SPSS?

Oliver, Richard
In reply to this post by jimjohn
Assumming all dates are have two-digit days and months and four digit years:

compute datevar=substr(datevar,1,10).

Otherwise, look for the space:

compute #space=index(datevar," ").
compute datevar=substr(datevar,1, #space-1).

To be on the safe side, you might want to create a copy of datevar first.


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of jimjohn
Sent: Thursday, July 17, 2008 12:54 PM
To: [hidden email]
Subject: How to truncate a variable in SPSS?

I have a date variable (a string) in the following format:
mm/dd/yyyy 0:00:00

I want to get rid of the 0:00:00 at the end of each of my values, because
otherwise it doesn't convert to a date format properly. Any suggestions on
what function I can use to do this? Thanks so much!
--
View this message in context: http://www.nabble.com/How-to-truncate-a-variable-in-SPSS--tp18514252p18514252.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: How to truncate a variable in SPSS?

Sara House
In reply to this post by jimjohn
You can do this by computing a variable that is a substring of the full variable:
 
STRING newdate (A10) .
COMPUTE newdate = SUBSTR(fulldate,1,10) .
 
This will create a new variable that takes the first 10 characters from your old date variable.  Of course, the new variable is a string, so you would need to convert it to a date.  I don't really do this often, so I went through the Date and Time Wizard from the transform menu and just had it past the syntax:
 
* Date and Time Wizard: datevar.
COMPUTE datevar = number(newdate, ADATE10).
VARIABLE LABEL datevar.
VARIABLE LEVEL datevar (SCALE).
FORMATS datevar (ADATE10).
VARIABLE WIDTH datevar(10).
EXECUTE.
 
I'm not sure if there is an easier way to do this.
 
Sara
 
Sara M. House, M.A.
Adjunct Faculty
Loyola University Chicago, Psychology Department
Email: [hidden email]
Teaching: Research Methods, Psychology & Law

AND

Data Analyst
Chicago Public Schools, Department of Program Evaluation
Email: [hidden email]

>>> jimjohn <[hidden email]> 7/17/2008 12:53 PM >>>
I have a date variable (a string) in the following format:
mm/dd/yyyy 0:00:00

I want to get rid of the 0:00:00 at the end of each of my values, because
otherwise it doesn't convert to a date format properly. Any suggestions on
what function I can use to do this? Thanks so much!
--
View this message in context: http://www.nabble.com/How-to-truncate-a-variable-in-SPSS--tp18514252p18514252.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: How to truncate a variable in SPSS?

mpirritano
In reply to this post by jimjohn
If the format is mm/dd/yyyy hh:mm:ss, with 2 digits for hour this IS an
spss date format. You can use xdate, xmonth, and xyear to extract these
from the original variable. Then you can you any of the Date.Dmy or
whatever format you want to create a simplified date format.

Matt

Matthew Pirritano, Ph.D.
Research Analyst IV
County of Orange
Medical Services Initiative (MSI)
[hidden email]
(714) 834-6011


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
jimjohn
Sent: Thursday, July 17, 2008 10:54 AM
To: [hidden email]
Subject: How to truncate a variable in SPSS?

I have a date variable (a string) in the following format:
mm/dd/yyyy 0:00:00

I want to get rid of the 0:00:00 at the end of each of my values,
because
otherwise it doesn't convert to a date format properly. Any suggestions
on
what function I can use to do this? Thanks so much!
--
View this message in context:
http://www.nabble.com/How-to-truncate-a-variable-in-SPSS--tp18514252p185
14252.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: How to truncate a variable in SPSS?

Oliver, Richard
First, the original variable isn't a date; it's a string. It would have to be converted to a date first. Second, I don't think the original variable isn't a valid SPSS date format because the Datetime format is unfortunately somewhat rigid and only recognizes dates of the general format d-m-y, not m-d-y.

Expanding on my previous post:

compute realdate=number(substr(stringdate,1,10),adate10).
formats realdate(adate10).

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Pirritano, Matthew
Sent: Thursday, July 17, 2008 1:42 PM
To: [hidden email]
Subject: Re: How to truncate a variable in SPSS?

If the format is mm/dd/yyyy hh:mm:ss, with 2 digits for hour this IS an
spss date format. You can use xdate, xmonth, and xyear to extract these
from the original variable. Then you can you any of the Date.Dmy or
whatever format you want to create a simplified date format.

Matt

Matthew Pirritano, Ph.D.
Research Analyst IV
County of Orange
Medical Services Initiative (MSI)
[hidden email]
(714) 834-6011


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
jimjohn
Sent: Thursday, July 17, 2008 10:54 AM
To: [hidden email]
Subject: How to truncate a variable in SPSS?

I have a date variable (a string) in the following format:
mm/dd/yyyy 0:00:00

I want to get rid of the 0:00:00 at the end of each of my values,
because
otherwise it doesn't convert to a date format properly. Any suggestions
on
what function I can use to do this? Thanks so much!
--
View this message in context:
http://www.nabble.com/How-to-truncate-a-variable-in-SPSS--tp18514252p185
14252.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

=====================
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: How to truncate a variable in SPSS?

Wincy Chan
In reply to this post by jimjohn
I used this to convert a date variable d5 (e.g. 17-MAR-2008 16:26:12) to a
numeric variable for date only:

COMPUTE date=XDATE.YEAR(d5)*10000 + XDATE.MONTH(d5)*100 + XDATE.MDAY(d5).

Hope it helps
Wincy



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
jimjohn
Sent: Friday, July 18, 2008 1:54 AM
To: [hidden email]
Subject: How to truncate a variable in SPSS?

I have a date variable (a string) in the following format:
mm/dd/yyyy 0:00:00

I want to get rid of the 0:00:00 at the end of each of my values, because
otherwise it doesn't convert to a date format properly. Any suggestions on
what function I can use to do this? Thanks so much!
--
View this message in context:
http://www.nabble.com/How-to-truncate-a-variable-in-SPSS--tp18514252p1851425
2.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