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

Removing decimal point from a string variable

670 views
Skip to first unread message

White, Robin HSURC

unread,
Nov 13, 1997, 3:00:00 AM11/13/97
to

Hi All,

I need to remove the decimal point from a string variable called
'Diagnosis' and have the new variable width = 5.

Any help on how to do this would be much appreciated.

Sample Data:

Diagnosis: Need it to look like:

009 009
481 481
592.4 5924
334.77 33477
V55.1 V551

(the decimal, if present, is always in the fourth column)

Thanks in advance for your help!

Sincerely,

Robin White,
Research Officer
Health Services Utilization and Research Commission
Saskatoon, SK, Canada
S7N 0W8
phone: (306) 655-6764
fax: (306) 655-1462
internet: whi...@sdh.sk.ca
http://www.sdh.sk.ca/hsurc/

Jeb

unread,
Nov 14, 1997, 3:00:00 AM11/14/97
to

Though SPSS no doubt offers some method to remove those pesky decimals, I've
found that my time is better spent learning skills which are actually
generalizable. Assuming your data set is not bigger than 65,536 rows by 256
columns, you can use Excel by going to Edit==>Replace, and entering "." in
the "Find what:" box. Leave the "Replace with:" box blank, hit OK, and all
your decimals will be removed. Other spreadsheets such as Quattro Pro have
similar features. You can easily transfer your file back and forth by
saving it as either a text file or in Excel 4.0 format. If you happen to be
using Unix, the grep command works even better.


J. Stone

Michael Lacy

unread,
Nov 15, 1997, 3:00:00 AM11/15/97
to

In article <97Nov14.10...@loon.sdh.sk.ca> "White, Robin HSURC" <whi...@SDH.SK.CA> writes:
>Hi All,
>
>I need to remove the decimal point from a string variable called
>'Diagnosis' and have the new variable width = 5.
>

I mocked up an example of your data problem, and the following SPSS syntax
did what you want. The original diagnosis variable is "diag", and the
new variable without the decimal place is "newdiag."


do if (index(diag,'.') = 4).
compute newdiag = concat( substr(diag,1,3), substr(diag,5) ).
else .
compute newdiag = diag.
end if .


Regards,

--
=-=-=-=-=-=-=-=-=-==-=-=-=
Mike Lacy, Sociology Dept., Colo. State Univ. FT COLLINS CO 80523
voice (970) 491-6721 fax (970) 491-2191

Rolf Kjoeller

unread,
Nov 15, 1997, 3:00:00 AM11/15/97
to

Hi Robin White.

At 17:08, 13 Nov 97, you wrote:

> I need to remove the decimal point from a string variable called
> 'Diagnosis' and have the new variable width = 5.

Try something like this:

DATA LIST LIST /dia (A6) .
BEGIN DATA
009
481
592.4
334.77
V55.1
Q.1234
Q1.234
Q12.34
Q123.4
END DATA .

/* If there is a dot the two parts of the diagnosis separated by the dot are
/* concatenated - if not the diagnosis is just copied to the new variable. As
/* you can see from the last four cases the dot doesn't have to be in the fourth
/*
column for things to work out.

STRING newdia (A5) .
DO IF INDEX(dia,".") GT 0 .
COMPUTE
newdia=CONCAT(SUBSTR(dia,1,INDEX(dia,".")-1),SUBSTR(dia,INDEX(dia,".")+1)).

ELSE .
COMPUTE newdia=dia .
END IF .
EXECUTE .

I hope this helps .

Rolf Kjoeller


===========================================
Rolf Kjoeller

e-mail: rolf_k...@vip.cybercity.dk
web: www2.dk-online.dk/users/rolf_kjoeller/front.htm
===========================================

0 new messages