Date: Fri, 26 May 2006 14:38:17 +0000
Reply-To: toby dunn <tobydunn@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: toby dunn <tobydunn@HOTMAIL.COM>
Subject: Re: Decimal Values and Places
In-Reply-To: <200605261417.k4QAkSq3032625@mailgw.cc.uga.edu>
Content-Type: text/plain; format=flowed
Jyothi ,
Multiple postings isnt going to get your question answered any faster, maybe
slower but definitly not faster.
I just notice something that disturbes me:
do over pd;
pd = put(pd,11.4);
end;
Looks like your trying to do an old style do loop with an array.
pd = put(pd,11.4);
Is Pd on the left hand side of the equal sign suppose to be the array
refernce, is the PD in the put function suppose to be a variable or an array
reference. When you make an array reference you need to do it like
PD(<index variable or value here>).
Also lets say the PD on the left and right hand side of the equals sign are
referncing a variable. Well SAS isnt going to like that. You are
attempting to change the type of a variable in mid stream, SAS doesnt like
this. The variable type is set at compile time and cannot be changed at
execution time.
So lets say you have a variable PD which is a numeric and you want to assign
its value up to the four decimal place to PD2 and you want PD2 to be a
character variable.
PD2 = Substr( put( PD , 11.5 ) , 1 , 10 ) ;
Now lets assume that you want PD2 to be a numeric:
PD2 = input( Substr( put( PD , 11.5 ) , 1 , 10 ) , 10.4 ) ;
I would guess that you could use some mathematical formula to transform the
numeric value originally in PD to the form you want, but when you do that
you darn well better have plenty of in code documentation explaining why
your doing this and how th e math works if it is complicated. No one like
to read code with magical numbers strewn through out and you cant count on
the person who is reading, using, or maintaining your code to be a math
wiz..
Toby Dunn
From: Jyothi Nekkalapudi <jnekkalapudi@GMAIL.COM>
Reply-To: Jyothi Nekkalapudi <jnekkalapudi@GMAIL.COM>
To: SAS-L@LISTSERV.UGA.EDU
Subject: Decimal Values and Places
Date: Fri, 26 May 2006 10:17:09 -0400
Hello,
I have a question regarding limiting the number of decimal values. In a
SAS dataset I have 8 variables whose values need to be restricted to 4
places and 2 variables whose values need to be restricted to 2 places.
If x = 54.46698 in the current SAS dataset, I want x = 54.4669.
I have used put function
do over pd;
pd = put(pd,11.4);
end;
which gives me a value of 54.467.
How can I avoid this rounding off and get the exact value and restrict the
decimal places.
Any help will be great. Thank You.