Create String Variable

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

Create String Variable

Ryan Mulligan-3
Dear List:

 

Using a string variable called Question, I want to create a new variable
based on the first two characters of this variable. I am creating the
new variable by going to Transform and then compute. I have tried to
using the string function Substring but get the following error "Invalid
combination of data types in an assignment. Character strings may only
be assigned to string variables. Numeric and logical quantities may only
be assigned to numeric variables. Consider using the STRING or Number
function."

 

Basically, I want to know how use string variable A to create string
variable B. String variable B should be based on the first two
characters of string variable A.

 

If anyone can help me with this simple task, I would really appreciate
it!

 

Thank You,

 

Ryan Mulligan

 

 

 

====================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: Create String Variable

Marks, Jim
You need to declare the string variable before computing it:


STRING newvar (A2).
COMPUTE newvar = SUBSTR(oldvar,1,2).

SPSS assumes that the COMPUTED variable is numeric, unless previously
declared/ defined

--jim



-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Ryan Mulligan
Sent: Wednesday, October 17, 2007 11:39 AM
To: [hidden email]
Subject: Create String Variable

Dear List:



Using a string variable called Question, I want to create a new variable
based on the first two characters of this variable. I am creating the
new variable by going to Transform and then compute. I have tried to
using the string function Substring but get the following error "Invalid
combination of data types in an assignment. Character strings may only
be assigned to string variables. Numeric and logical quantities may only
be assigned to numeric variables. Consider using the STRING or Number
function."



Basically, I want to know how use string variable A to create string
variable B. String variable B should be based on the first two
characters of string variable A.



If anyone can help me with this simple task, I would really appreciate
it!



Thank You,



Ryan Mulligan







=======
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: Create String Variable

Lombardo, Barbara
In reply to this post by Ryan Mulligan-3
Ryan,

Your substring function will work if you have A and B both set to string
types.  Your error message says one of your variables is a number.





Barbara Lombardo

Camden County College
Institutional Research
856-374-4961


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Ryan Mulligan
Sent: Wednesday, October 17, 2007 12:39 PM
To: [hidden email]
Subject: Create String Variable

Dear List:



Using a string variable called Question, I want to create a new variable
based on the first two characters of this variable. I am creating the
new variable by going to Transform and then compute. I have tried to
using the string function Substring but get the following error "Invalid
combination of data types in an assignment. Character strings may only
be assigned to string variables. Numeric and logical quantities may only
be assigned to numeric variables. Consider using the STRING or Number
function."



Basically, I want to know how use string variable A to create string
variable B. String variable B should be based on the first two
characters of string variable A.



If anyone can help me with this simple task, I would really appreciate
it!



Thank You,



Ryan Mulligan







=======
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: Create String Variable

Ornelas, Fermin-2
COMPUTE #BENYR=TRUNC(BENMO/100)
COMPUTE #BENMN=MOD(BENMO,10)
COMPUTE  BDATE=DATE.MDY(#BENMN,1,#BENYR)
COMPUTE #YR= TRUNC(ISSDATE/1E4)
COMPUTE #MO= TRUNC(MOD(ISSDATE,1E4)/1E2)
COMPUTE #DA= MOD(ISSDATE,1E2)
COMPUTE IDATE=86400*YRMODA(#YR,#MO,#DA)
FORMAT IDATE(ADATE)
       BDATE(ADATE)

Here is a trick that was given to me by the list when one has a variable
that is numeric. The substring command as Barbara said requires the
variable to be alpha numeric. You could also convert it first to string.

Here is another example
 STRING SITE2   (A4)
COMPUTE SITE2=STRING(SITE,F4.0)

This is a numerical variable that has been changed to numeric. On site2
I can use the substr command

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Lombardo, Barbara
Sent: Wednesday, October 17, 2007 10:28 AM
To: [hidden email]
Subject: Re: Create String Variable

Ryan,

Your substring function will work if you have A and B both set to string
types.  Your error message says one of your variables is a number.





Barbara Lombardo

Camden County College
Institutional Research
856-374-4961


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Ryan Mulligan
Sent: Wednesday, October 17, 2007 12:39 PM
To: [hidden email]
Subject: Create String Variable

Dear List:



Using a string variable called Question, I want to create a new variable
based on the first two characters of this variable. I am creating the
new variable by going to Transform and then compute. I have tried to
using the string function Substring but get the following error "Invalid
combination of data types in an assignment. Character strings may only
be assigned to string variables. Numeric and logical quantities may only
be assigned to numeric variables. Consider using the STRING or Number
function."



Basically, I want to know how use string variable A to create string
variable B. String variable B should be based on the first two
characters of string variable A.



If anyone can help me with this simple task, I would really appreciate
it!



Thank You,



Ryan Mulligan







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

NOTICE: This e-mail (and any attachments) may contain PRIVILEGED OR
CONFIDENTIAL information and is intended only for the use of the
specific individual(s) to whom it is addressed.  It may contain
information that is privileged and confidential under state and federal
law.  This information may be used or disclosed only in accordance with
law, and you may be subject to penalties under law for improper use or
further disclosure of the information in this e-mail and its
attachments. If you have received this e-mail in error, please
immediately notify the person named above by reply e-mail, and then
delete the original e-mail.  Thank you.

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