Date: Wed, 8 Apr 2009 13:19:43 -0400
Reply-To: Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Subject: Re: Find the First Position of the Character
only the first 0 or the first char? Another idea to replace the first 0
with 1:
data _null_ ;
input pt $ ;
pos=index(pt,"0");
if pos then substr(pt,pos,1)="1";
put pt= ;
datalines;
000047
555555
999909
;
run ;
Gerhard
On Wed, 8 Apr 2009 11:59:51 -0400, Ken Borowiak <evilpettingzoo97@AOL.COM>
wrote:
>On Wed, 8 Apr 2009 11:43:28 -0400, SAS_learner <proccontents@GMAIL.COM>
>wrote:
>
>>Hello _all_,
>>
>>I am Seq Number = "000047" and I need to replace the First 0 with 1 so
>>that result PT = "100047" For that I am trying something like this
>>
>>Pt = Strip(Tranwrd(Substr(Sequence,*1*,*1*),"0","1") ) ;
>>
>>But gives me Just the First letter any better Idea How to get this done
>>
>>
>>
>>TIA
>>SL
>
>SL,
>
>You can use PRXCHANGE to make the substitution:
>
>data _null_ ;
>input pt $ ;
> length new_pt $8 ;
> new_pt=prxchange( 's/0/1/io', 1 , pt ) ;
> put (pt new_pt)(=) ;
>datalines;
>000047
>555555
>999909
>;
>run ;
>
>SAS log:
>pt=000047 new_pt=100047
>pt=555555 new_pt=555555
>pt=999909 new_pt=999919
>
>The 1 in the second argument of PRXCHANGE says to make the pattern
>substitution just once. 2 would means make it twice, etc. and -1 means
>change them all.
>
>Regards,
>Ken Borowiak
|