Date: Wed, 9 Apr 2008 14:22:33 -0700
Reply-To: Bill McKirgan <Bill.McKirgan@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Bill McKirgan <Bill.McKirgan@GMAIL.COM>
Subject: Re: How to add zeros ahead of numeric data
Content-Type: text/plain; charset=ISO-8859-1
On Apr 9, 3:52 pm, jn_...@YAHOO.COM (jn mao) wrote:
> Hi SAS-Ls,
> I have some character type's number data. I need to add '00' or '0' before the numbers and still keep them as charcter type data.
> raw data (chacter type):
> wanted data (character type):
> The raw data are character type data, so I did convert them to numberic data, then time 100, eg. 8.8---> 880, and then I convert them back to character data, then I use CAT function to add '00' ahead the character data. However, there always with many spaces between the '00' and the numbers, like 00 880
> How do I delete these spaces? and how can I have the right format data?
> Here is my code for adding zeros for new character data:
> new_cha=put(raw_num, best14.)
> if 0<raw_num<10 then new_cha=cat('00',new_cha);
> if 10<raw_num<100 then new_cha=cat('0',new_cha);
> Thanks much,
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection aroundhttp://mail.yahoo.com
The z. format is helpful here. I had to fiddle around abit to see
what needed to be done to get the decimal removed and insert the
desired trailing zeros as well, but I think this might work for what
input a $;
format a_num z6.1;
*put a @10 a_num;
b = compress(put(a_num,z6.2),'.');
NOTE: There were 2 observations read from the data set WORK.RAW.
NOTE: The data set WORK.WANTED has 2 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds