Modifying Numeric Values with Functions

SAS provides additional functions to create or modify numeric values. These include arithmetic, financial, and probability functions. This book covers the following selected functions.

CEIL and FLOOR Functions

To return integers that are greater than or equal to the argument, use these functions:
  • The CEIL function returns the smallest integer that is greater than or equal to the argument.
  • The FLOOR function returns the largest integer that is less than or equal to the argument.
Syntax, CEIL and FLOOR function:
CEIL(argument)
FLOOR(argument)
argument is a numeric variable, constant, or expression.
If the argument is within 1E-12 of an integer, the function returns that integer.
The following SAS statements produce this result:
Table 14.12 CEIL and FLOOR Functions
SAS Statement
Result
CEIL Function Examples
data _null_;
  var1=2.1;
  var2=-2.1;
  a=ceil(var1);
  b=ceil(var2);
  put "a=" a;
  put "b=" b;
run;
a=3
b=-2
data _null_;
  c=ceil(1+1.e-11);
  d=ceil(-1+1e-11);
  e=ceil(1+1.e-13)
  put "c=" c;
  put "d=" d;
  put "e=" e;
run;
c=2
d=0
e=1
data _null_;
  f=ceil(223.456);
  g=ceil(763);
  h=ceil(-223.456);
  put "f=" f;
  put "g=" g;
  put "h=" h;
run;
f=224
g=763
h=-223
FLOOR Function Examples
data _null_;
  var1=2.1;
  var2=-2.1;
  a=floor(var1);
  b=floor(var2);
  put "a=" a;
  put "b=" b;
run;
a=2
b=-3
data _null_;
  c=floor(1+1.e-11);
  d=floor(-1+1e-11);
  e=floor(1+1.e-13)
  put "c=" c;
  put "d=" d;
  put "e=" e;
run;
c=1
d=-1
e=1
data _null_;
  f=floor(223.456);
  g=floor(763);
  h=floor(-223.456);
  put "f=" f;
  put "g=" g;
  put "h=" h;
run;
f=223
g=763
h=-224

INT Function

To return the integer portion of a numeric value, use the INT function. Any decimal portion of the INT function argument is discarded.
Syntax, INT function:
INT(argument)
argument is a numeric variable, constant, or expression.
The two data sets shown below give before-and-after views of values that are truncated by the INT function.
data work.creditx; 
  set cert.credit; 
  Transaction=int(transaction); 
run;
proc print data=work.creditx;
run;
Output 14.18 INT Function Comparison
INT Function Comparison

ROUND Function

To round values to the nearest specified unit, use the ROUND function.
Syntax, ROUND function:
ROUND(argument,round-off-unit)
  • argument is a numeric variable, constant, or expression.
  • round-off-unit is numeric and nonnegative.
If a rounding unit is not provided, a default value of 1 is used, and the argument is rounded to the nearest integer. The two data sets shown below give before-and-after views of values that are modified by the ROUND function. The first ROUND function rounds the variable AccountBalance to the nearest integer. The second ROUND function rounds the variable InvoicedAmount to the nearest tenth decimal place. The third ROUND function rounds the variable AmountRemaining to the nearest hundredth decimal place.
data work.rounders; 
  set cert.rounders; 
  AccountBalance=round(AccountBalance, 1);
  InvoicedAmount=round(InvoicedAmount, 0.1);
  AmountRemaining=round(AmountRemaining, 0.02);
  format AccountBalance InvoicedAmount PaymentReceived AmountRemaining dollar9.2;
run;
proc print data=work.rounders;
run;
Output 14.19 Before and After ROUND Function
The graphic displays the transaction variable before and after ROUND function was applied to the transaction variable.
Last updated: August 23, 2018
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.254.118