|
1. You probably want to use CEIL, as others have suggested.
2. The simplest way to do it with ROUND is probably
t3 = round(total + 0.5);
3. However, you have to pay attention to boundary cases. How will my
formula in #2 behave when TOTAL is an integer? Your code will leave T3 as
a missing value since it does not handle T2=TOTAL.
4. If negative values of TOTAL are possible, you may not want to use CEIL.
It depends on whether "up" means up in magnitude or up toward zero.
On Fri, 3 Dec 2004 05:44:07 -0500, ben.powell@CLA.CO.UK wrote:
>Dear SAS-L
>
>Is this the best way to round up a variable to the nearest integer?
>
>data temp;
>input total;
>cards;
>1277.5
>232.46
>430.36
>0.38
>6.4
>;
>
>data temp2;
>set temp;
>t2 = round(total);
>if t2 > total then t3 = t2;
>if t2 < total then do;
> t2 = total + 0.5;
> t3 = round(t2);
>end;
>drop t2;
>run;
>
>
>Regards,
>Ben.
>3 2000
>4 2500
>;
>
>DATA LimitData;
>INPUT Acc_No Limit;
>CARDS;
>1 1500
>2 2000
>3 2500
>5 3000
>;
>RUN;
>
>PROC SQL;
>CREATE TABLE CardData
>AS
>SELECT COALESCE(A.Acc_No, B.Acc_No) AS Acc_No, A.Balance, B.Limit
>FROM CardData AS A Full Join LimitData AS B
>ON A.Acc_No = B.Acc_No
>;
>QUIT;
>
>Thanks
>
>Richard Crawley-Boevey
|