Removing last two digits from Number

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

klabnix
Posts: 1
Joined: Thu Jun 30, 2016 10:42 am

Removing last two digits from Number

Postby klabnix » Thu Jun 30, 2016 10:52 am

If I have a numeric CASEID variable with numbers like this:

101
201
301
1101
1201
4101
399501
401201

What syntax can I use to remove the last two digits so it looks like:

1
2
3
11
12
41
3995
4012

I just want to cut all the "01" off that the end. I can find how to do this if all the cases have the same number of characters but not if they differ in number.

eg, the following syntax would work if each ID was 4 characters long, but in my case they range from 3 to 6 characters.
string newCASEID (A4).
compute newCASEID = substr(CASEID, 1, 4).
EXECUTE.


I presume it's easiest to change the numeric variable to string first,


It would be interesting to know how to do this in reverse to add a certain digit at the end but I think this is easier to find out online.

Many thanks



(SPSS version 23)

Who is online

Users browsing this forum: No registered users and 1 guest

cron