[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 343

# Pickup just last 16 digits

i have records like

000000000189766666554444
1111111111114561111111111111
2222222224555555555555555555
44444444444447855555555
8976

i want to pickup just last 16 digits if rows has more then 16 digits else no change required
so result should be

0189766666554444
4561111111111111
5555555555555555
4444447855555555
8796

Thanks
0
sam2929
1 Solution

Commented:
you could do something ilke:

data x;
x="1234567890123456";
lenX = length(x);
if (lenX > 16) then
y=substr(x, length(x) - 15);
else
y = x;
run;
0

Commented:
In SQL, try something like this:
``````drop table #t
create table #t(a varchar(100))
insert into #t values('000000000189766666554444')
insert into #t values('1111111111114561111111111111')
insert into #t values('2222222224555555555555555555')
insert into #t values('44444444444447855555555')
insert into #t values('8976')
select case when LEN(a)< 16 then a else RIGHT(a,16) end as outint from #t
``````
0

## Featured Post

Tackle projects and never again get stuck behind a technical roadblock.