```Date: Thu, 30 Oct 2008 09:28:49 -0400 Reply-To: "Howard Schreier " Sender: "SAS(r) Discussion" From: "Howard Schreier " Subject: Re: Help in Completing with zeros On Thu, 30 Oct 2008 09:21:31 -0400, Jack Clark wrote: >Ricardo, > >Convert from numeric to character using the PUT function and the z8. >format. This will add leading zeros to numbers with less than 8 digits. >Then, substring to get the first two bytes. > > >data _null_; >x=3121212; >CEP= SUBSTR(PUT(x,z8.),1,2) ; >put _all_; >run; > >Jack Clark >Senior Research Analyst >phone: 410-455-6256 >fax: 410-455-6850 >jclark@hilltop.umbc.edu > >University of Maryland, Baltimore County >Sondheim Hall, 3rd Floor >1000 Hilltop Circle >Baltimore, MD 21250 > -----Original Message----- >From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of >Ricardo Silva >Sent: Thursday, October 30, 2008 8:43 AM >To: SAS-L@LISTSERV.UGA.EDU >Subject: Help in Completing with zeros > >Hi, > >This question is related with another I posted two days ago, concerning >the selection of the first two digits of a number. I'm using the >following statment: > > >CEP= SUBSTR(STRIP(PUT(X,BEST32.)),1,2)*1 ; > >which is working well. > > > >However, the variable X must contain 8 digits, but sas is hiding the >zeros (0) when it is in the begning of the number, p.e., 03121212 >appears as 3121212. So when I select the 2 digits I need I got 31 >instead of 03. > >How can I fix this? > >Thanks, > >Rick It seems that X is numeric and CEP is supposed to be numeric. So get rid of all the type conversions. Try: data _null_; X = 3121212; CEP = floor( X / 1e6 ); format CEP z2.; put _all_; run; ```

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