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

Shortening, chopping off, truncating part of a number

310 views
Skip to first unread message

bertma...@yahoo.com

unread,
Jan 5, 2006, 3:03:30 PM1/5/06
to
I've searched for an answer but I think my lack of familiarity with
SPSS lingo is hindering the search. In Access I would truncate the
number but it appears in SPSS TRUNC is about decimals. I'm sure this
must be simple.

We have client ID numbers that are 7 digits long. I want a new variable
that just has the last 2 digits.

For Example:

Old Variable New Variable
4387801 01

Bruce Weaver

unread,
Jan 5, 2006, 3:21:03 PM1/5/06
to

This assumes your original ID variable is numeric, and always has 7
digits.

* --------------------------------------- .
data list list /id (f7.0).
begin data
4387801
end data.

string newid(a2).
compute newid = substr(string(id,f7),6,2).
list.
* --------------------------------------- .

If the original ID variable is already a string variable, change the
COMPUTE to:

compute newid = substr(id,6,2).

--
Bruce Weaver
bwe...@lakeheadu.ca
www.angelfire.com/wv/bwhomedir

bertma...@yahoo.com

unread,
Jan 5, 2006, 6:00:02 PM1/5/06
to
Thanks Bruce. But I've got to ask a stupid question. If I have 1000 ID
numbers I want to do this with how do I indicate that. Is there a way
to replace the:
"begin data
4387901
end data"

with the variable name so it does this for the entire column instead of
for the numbers listed. I'm not sure if that was what it was supposed
to do but it did. I also tried entering the lowest and highest numbers
but I only got results for those two. It is numeric and always 7 digits
also.

neila...@msn.com

unread,
Jan 5, 2006, 7:01:01 PM1/5/06
to
data list free/ num7 .
begin data
2345267
4566283
8458746
6474823
end data.
*Drum beat, Bruce winces, smacks himself upside the head....*.
compute smackme=MOD(num7,100).
FORMAT smackme (N2).
list.
NUM7 SMACKME

2345267 67
4566283 83
8458746 46
6474823 23
Are we having fun yet????
Neila

Bruce Weaver

unread,
Jan 6, 2006, 7:07:45 AM1/6/06
to

Everything from "data list" to "end data" was just a way to get some
data into the data editor for demonstration purposes. I assume you have
your real data in a file already, so you can omit those lines.

Bruce Weaver

unread,
Jan 6, 2006, 7:12:49 AM1/6/06
to

Right, I forgot about that N-format, which ensures that leading 0's are
displayed. I.e., if the first ID number was 2345207, SMACKME would
display as 07 (because of the N2 format).

num7 smackme

2345207 07


4566283 83
8458746 46
6474823 23

bertma...@yahoo.com

unread,
Jan 6, 2006, 1:08:31 PM1/6/06
to
Thanks much for your patience. I got it this time. I'm really new at
SPSS (well, except when I was in college about 25 years ago and used it
on a mainframe). There are some good online video tutorials at UCLA on
SPSS syntax. I'm sure I'll learn more so that I really understand what
I'm doing rather than just following instructions.

Message has been deleted
0 new messages