Converting string values with the wrong decimal separator into numric values

  • Follow


Hi,

I have a large dataset with blood sample results as string variables
due to a possible outcome of <0,01 (not my choice - the lab send me
the results in an excel spreadsheet formatted this way)
..
I've recoded the variable (REPLY.1) into a new one (REPLY.1N) where
<0,01 => 0 and all other values are the kept. This to get rid of the
"<".

However, when I use:

recode REPLY.1 (convert) into REPLY.1N.
execute.

to get numeric values only the 0's (zeroes) are kept.
All other values (eg. 1,24; 5,10; 0,32 etc.) are listed as missing.

I suspect it is because the decimal separator used in the original
string variable (REPLY.1) is a comma.

How can I convert REPLY.1 into a numeric variable without loosing all
the important results?


Thanks in advance

Jacob Sorensen

0
Reply Jacob 2/23/2010 9:41:32 AM

On Feb 23, 4:41=A0am, Jacob <jacobthors...@gmail.com> wrote:
> Hi,
>
> I have a large dataset with blood sample results as string variables
> due to a possible outcome of <0,01 (not my choice - the lab send me
> the results in an excel spreadsheet formatted this way)
> .
> I've recoded the variable (REPLY.1) into a new one (REPLY.1N) where
> <0,01 =3D> 0 and all other values are the kept. This to get rid of the
> "<".
>
> However, when I use:
>
> recode REPLY.1 (convert) into REPLY.1N.
> execute.
>
> to get numeric values only the 0's (zeroes) are kept.
> All other values (eg. 1,24; 5,10; 0,32 etc.) are listed as missing.
>
> I suspect it is because the decimal separator used in the original
> string variable (REPLY.1) is a comma.
>
> How can I convert REPLY.1 into a numeric variable without loosing all
> the important results?
>
> Thanks in advance
>
> Jacob Sorensen


Use the REPLACE function to replace all of the commas in REPLY.1 with
periods before converting it to a numeric variable.

compute REPLY.1 =3D replace(REPLY.1,",",.").
recode REPLY.1 (convert) into REPLY.1N.
execute.

--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/Home
"When all else fails, RTFM."
0
Reply Bruce 2/23/2010 12:20:50 PM


On Feb 23, 2:20=A0pm, Bruce Weaver <bwea...@lakeheadu.ca> wrote:
> On Feb 23, 4:41=A0am, Jacob <jacobthors...@gmail.com> wrote:
>
>
>
> > Hi,
>
> > I have a large dataset with blood sample results as string variables
> > due to a possible outcome of <0,01 (not my choice - the lab send me
> > the results in an excel spreadsheet formatted this way)
> > .
> > I've recoded the variable (REPLY.1) into a new one (REPLY.1N) where
> > <0,01 =3D> 0 and all other values are the kept. This to get rid of the
> > "<".
>
> > However, when I use:
>
> > recode REPLY.1 (convert) into REPLY.1N.
> > execute.
>
> > to get numeric values only the 0's (zeroes) are kept.
> > All other values (eg. 1,24; 5,10; 0,32 etc.) are listed as missing.
>
> > I suspect it is because the decimal separator used in the original
> > string variable (REPLY.1) is a comma.
>
> > How can I convert REPLY.1 into a numeric variable without loosing all
> > the important results?
>
> > Thanks in advance
>
> > Jacob Sorensen
>
> Use the REPLACE function to replace all of the commas in REPLY.1 with
> periods before converting it to a numeric variable.
>
> compute REPLY.1 =3D replace(REPLY.1,",",.").
> recode REPLY.1 (convert) into REPLY.1N.
> execute.
>
> --
> Bruce Weaver
> bwea...@lakeheadu.cahttp://sites.google.com/a/lakeheadu.ca/bweaver/Home
> "When all else fails, RTFM."

My version of SPSS (13.0) doesn't seem to have a REPLACE function, but
if I were you, I'd do the replacement (of , into .) in Excel, before
importing the file into SPSS.
Another option is to - temporarily - change the default decimal
separator in your operating system. If it's Windows, you do that in
Control panel > Regional and language options.

0
Reply WimN 2/23/2010 5:52:47 PM

WimN <wimneel@gmail.com> writes:

> Another option is to - temporarily - change the default decimal
> separator in your operating system. If it's Windows, you do that in
> Control panel > Regional and language options.

Or just:
        SET DECIMAL=COMMA.
        ...recode commands...
        SET DECIMAL=DOT.
-- 
Ben Pfaff 
http://benpfaff.org
0
Reply Ben 2/23/2010 6:12:02 PM

Thank you all very much for your help.


Jacob
0
Reply Jacob 2/24/2010 9:34:04 AM

4 Replies
1172 Views

(page loaded in 0.332 seconds)

Similiar Articles:













7/20/2012 2:47:09 PM


Reply: