Q:

Replacing a varying number of leading consecutive symbols in string in SAS

In SAS I have an alphanumeric ID variable in my dataset with values consisting of 12 symbols.
DATA new;
  input id $12.;
  datalines;
  00007047611B
  00649252842B
  00837530027V
  00000004627K
;
RUN;

I want to replace ONLY the leading zeros by underscores (_) to get the following format:
____7047611B
__649252842B
__837530027V
_______4627K
I have already tried to use substr together with tranwrd or translate, however the varying number of leading zeros proved problematic.

Possible solution based on Tom's suggestion:
DATA new;
  input id $12.;
  datalines;
  00007047611B
  00649252842B
  00837530027V
  00000004627K
;
RUN;

DATA new;
  set new;
  pos = verify(id, "0");
  id = cats(repeat('_', pos - 2), substr(id, pos));
RUN; 

A:

Good example for SUBSTR-on-the-left.
65   data _null_;
66      input id :$12.;
67      put id=;
68      if id eq: '0' then substr(id,1,verify(id,'0')-1)='____________';
69      put id=;
70      cards;

id=00007047611B
id=____7047611B
id=00649252842B
id=__649252842B
id=00837530027V
id=__837530027V
id=00000004627K
id=_______4627K
id=90007047611B
id=90007047611B
id=04007047611B
id=_4007047611B

A:

Here is one way
data have;
input id $ 12.;
datalines;
00007047611B
00649252842B
00837530027V
00000004627K
;

data want (keep=id);
    set have;
    rid = prxparse("/^(0*)/");
    m = prxmatch(rid, id);
    call prxposn(rid, 1, pos, len);
    id = cats(repeat('_', len-1), substr(id, len+1));
run;

