Date: Thu, 30 Oct 2008 09:28:49 -0400
Reply-To: "Howard Schreier <hs AT dc-sug DOT org>"
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Howard Schreier <hs AT dc-sug DOT org>"
Subject: Re: Help in Completing with zeros
On Thu, 30 Oct 2008 09:21:31 -0400, Jack Clark <jclark@HILLTOP.UMBC.EDU> wrote:
>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.
>CEP= SUBSTR(PUT(x,z8.),1,2) ;
>Senior Research Analyst
>University of Maryland, Baltimore County
>Sondheim Hall, 3rd Floor
>1000 Hilltop Circle
>Baltimore, MD 21250
>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
>Sent: Thursday, October 30, 2008 8:43 AM
>Subject: Help in Completing with zeros
>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
>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?
It seems that X is numeric and CEP is supposed to be numeric. So get rid of
all the type conversions. Try:
X = 3121212;
CEP = floor( X / 1e6 );
format CEP z2.;