Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help converting string to numeric without losing data

518 views
Skip to first unread message

lizg

unread,
Aug 1, 2001, 10:36:54 PM8/1/01
to
Help! When our data was imported, the numeric data was changed into
string variables. I need to quickly convert the string variables back
into numeric variables without losing the data. I tried using the
conversion function but no luck (or maybe I am doing it wrong?)

Thank you,
Liz

Svein Åge Relling

unread,
Aug 2, 2001, 3:23:03 AM8/2/01
to
To convert a string variable into a numeric where all cases a are numbers,
simply use this syntax:

RECODE VSTRING (CONVERT) INTO VNUMERIC.

where VSTRING is the string variable and VNUMERIC is the new numeric
variable.

If some cases contain alphanumeric data you can specify which values these
should be recoded into: e.g.:

RECODE VSTRING (CONVERT) ('-' = 11)('&' = 12) INTO VNUMERIC.

Otherwise, cases with other alphanumeric data will be recoded into "system
missing".

Svein Åge Relling
Trondheim kommune, Norway

Randall C. Fasnacht, Sr.

unread,
Aug 2, 2001, 6:36:22 AM8/2/01
to
A typical approach:

ABCX = the original string "number"

NUMX = new number you want

Two different approaches - both should work:

COMPUTE NUMX = NUM(ABCX, F5.0). /* use whatever format you want in "F5.0"
EXECUTE.

or

RECODE ABCX (CONVERT) INTO NUMX.
FORMAT NUMX (F5.0).
EXECUTE.


Good Luck

li...@unr.nevada.edu (lizg) wrote in message news:<5bad192.01080...@posting.google.com>...

lizg

unread,
Aug 2, 2001, 11:00:38 AM8/2/01
to

I've also tried this code, which does the same thing (new variable, no
data converted - blank cells instead).

RECODE poc1_1 (CONVERT) INTO trynow.

0 new messages