Hi, Data want; set have; if substr(thevariable,1,2)="40" and length(strip(thevariable))=8 then substr(thevariable,3); else if substr(thevariable,1,3)="400" and length(strip(thevariable))=9 then substr(thevariable,4); run; You should be aware though your logic seems to overlap as 400 appears for each record. So only the length check is really necessary, i.e. if length(strip(thevariable))=8 then substr(2..), else sustr(3...). Just thought also, you could also reverse the string and take the first 8 characters, then reverse again. Or you could also right() the string, take the last 8 characters and then left e.g substr(right(thevariable),length(right(thevariable)-8);
... View more