LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2007, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sat, 7 Jul 2007 11:49:53 -0400
Reply-To:     Ken Borowiak <EvilPettingZoo97@AOL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ken Borowiak <EvilPettingZoo97@AOL.COM>
Subject:      Re: Formatting hexadecimal output

On Sat, 7 Jul 2007 10:51:39 +0200, Robert Bardos <bardos2@ANSYS.CH> wrote:

>> -----Original Message----- >> Horne, Jim - James S >> Gesendet: Freitag, 6. Juli 2007 18:49 >> Betreff: Formatting hexadecimal output >> >> >> I have a field in HEX4. format and I want to eliminate >> all leading zeroes when I display it. >> I want 0 to be 0 instead of 0000, >> 4 to be 4 instead of 0004 and 0EC6 to be EC6. >> >> Does anyone know how to do this? I'm stumped! >> >> Jim Horne > > >Wouldn't that be an easy one for PRXCHANGE? > > >Something like .... haven't got the slightest idea >and my 9.1.3 licence has just expired. > >Ken? David? Toby? > > >Robert

Jim,

Robert writes sooth, PRXCHANGE can help you out here. So the rule to apply is 'trim all leading zeroes, unless they are all zeroes in which you want to keep a single 0'.

data have ; input x $4. ; j=input(x,hex4.) ; datalines; 0000 0004 0EC6 AEC1 ; run ;

data need ; re=prxparse('s/^0+(\w+)$/$1/') ; if missing( re ) then stop ;

length y $4 ; do until( eof ) ; set have end=eof ; y=prxchange( re, -1, x ) ; output ; put (x y)(=) ; end ; stop ; run ;

SAS log: x=0000 y=0 x=0004 y=4 x=0EC6 y=EC6 x=AEC1 y=AEC1

Substitution regex: s/^0+(\w+)$/$1/

After first '/' - this is the matching part of the regex ^ : Assert position at beginning of field 0+ : Match '0' one or more times (greedily) ( ) : Capture submatch in backreference #1 \w+ : match one or more 'word' characters (greedily) $ : Assert position at end of the field

After second '/' - this is the replacement part of the regex $1 : keep only what is in backreference #1

HTH, Ken


Back to: Top of message | Previous page | Main SAS-L page