How to get the last 2 digits from a numeric value

Reply
Occasional Contributor
Posts: 13

How to get the last 2 digits from a numeric value

Hi Guys,

I am trying to get the last 2 digits from a numeric field. Can you please assist:

If the value is 101234 then I want my output to be 34.

Thanks in advance.

Super Contributor
Posts: 336

Re: How to get the last 2 digits from a numeric value

You're looking for the modulo-function: mod(101234,100) gives 34.

Occasional Contributor
Posts: 13

Re: How to get the last 2 digits from a numeric value

Works like a charm. Thanks.

Occasional Learner
Posts: 1

Re: How to get the last 2 digits from a numeric value

Worked great.I wanted to get the output where the the numeric values in a column are not incremented by 100.Example:I want to see where the values are 150,192 etc.The valid values are only 100,200,300... etc. I used in proc sql as

and mod(a.XXXXX_AM,100)<>0 and worked great.

Occasional Contributor
Posts: 6

Re: How to get the last 2 digits from a numeric value

Hi Avenue,

following code will assist you to resolve your problem:

DATA _null_;

  x1=101234;

  x2=INPUT(SUBSTR(PUT(x1,best.),LENGTH(PUT(x1,best.))-2+1),2.);

  PUT x2=;

RUN;

Ask a Question
Discussion stats
  • 4 replies
  • 3487 views
  • 3 likes
  • 4 in conversation