Converting Mixed String-Numeric Variables

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

Converting Mixed String-Numeric Variables

Krinsky, Alan
I am having difficulty transforming or computing a new variable for
identification variables starting with 2 letters followed by several
numbers. I would prefer to keep the two letters for identification and
drop all of the numbers to the right of these, but every approach I try
seems to get blocked. If I use a command that treats the original
variable as a string, the error message suggests a numeric variable or
argument is missing, and if I treat the original variable as numeric
there is an error message in search of a string variable. So, I cannot
get something as simple as LTrim or RTrim to work. I tried first
converting the original variable into string or numeric (according to
the variable definitions, it is a string), but I am getting similar
error messages. Any ideas?


Alan D. Krinsky  PhD, MPH
Worcester, MA




The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential and/or
privileged material.  Any review, transmission, re-transmission,
dissemination or other use of, or taking of any action in reliance
upon this information by persons or entities other than the
intended recipient is prohibited.  If you received this in error,
please contact the sender and delete the material from any
computer.

====================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: Converting Mixed String-Numeric Variables

ViAnn Beadle
Provide an example of your existing variable(s) and your desired new
variable.

-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Krinsky, Alan
Sent: Wednesday, July 02, 2008 7:36 AM
To: [hidden email]
Subject: Converting Mixed String-Numeric Variables

I am having difficulty transforming or computing a new variable for
identification variables starting with 2 letters followed by several
numbers. I would prefer to keep the two letters for identification and
drop all of the numbers to the right of these, but every approach I try
seems to get blocked. If I use a command that treats the original
variable as a string, the error message suggests a numeric variable or
argument is missing, and if I treat the original variable as numeric
there is an error message in search of a string variable. So, I cannot
get something as simple as LTrim or RTrim to work. I tried first
converting the original variable into string or numeric (according to
the variable definitions, it is a string), but I am getting similar
error messages. Any ideas?


Alan D. Krinsky  PhD, MPH
Worcester, MA




The information transmitted is intended only for the person or
entity to which it is addressed and may contain confidential and/or
privileged material.  Any review, transmission, re-transmission,
dissemination or other use of, or taking of any action in reliance
upon this information by persons or entities other than the
intended recipient is prohibited.  If you received this in error,
please contact the sender and delete the material from any
computer.

=======
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:Converting Mixed String-Numeric Variables

Jerabek Jindrich
In reply to this post by Krinsky, Alan
Hello,

I guess You have an ID variable in the following format:

ID
AB0001
XZ1234 ........

And  want to split into AB and 0001.

STRING ID1str (A2).
STRING ID2str (A10).

COMPUTE ID1str = substr(ID,1,2).
COMPUTE ID2str = substr(ID,3).

The syntax above creates 2 new strings and saves separately the leading two letters and following numbers.


You can change the second string into a numeric variable:
COMPUTE ID2int = NUMBER(id2str,F10.0).

HTH
Jindra


> ------------ Původní zpráva ------------
> Od: Krinsky, Alan <[hidden email]>
> Předmět: Converting Mixed String-Numeric Variables
> Datum: 02.7.2008 16:00:08
> ----------------------------------------
> I am having difficulty transforming or computing a new variable for
> identification variables starting with 2 letters followed by several
> numbers. I would prefer to keep the two letters for identification and
> drop all of the numbers to the right of these, but every approach I try
> seems to get blocked. If I use a command that treats the original
> variable as a string, the error message suggests a numeric variable or
> argument is missing, and if I treat the original variable as numeric
> there is an error message in search of a string variable. So, I cannot
> get something as simple as LTrim or RTrim to work. I tried first
> converting the original variable into string or numeric (according to
> the variable definitions, it is a string), but I am getting similar
> error messages. Any ideas?
>
>
> Alan D. Krinsky  PhD, MPH
> Worcester, MA
>
>
>
>
> The information transmitted is intended only for the person or
> entity to which it is addressed and may contain confidential and/or
> privileged material.  Any review, transmission, re-transmission,
> dissemination or other use of, or taking of any action in reliance
> upon this information by persons or entities other than the
> intended recipient is prohibited.  If you received this in error,
> please contact the sender and delete the material from any
> computer.
>
> ???????
> 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