Study guide
5.2 Numeric & Mathematical Functions
SAS Certified Specialist: Base Programming Using SAS 9.4 A00-231
Track your progress as you read
Finished sections get a check mark.
1 Chapter 1: SAS Base Programming Exam Overview
1.1 A00-231 Exam Format, Scoring & Test-Day Logistics 1.2 Official Content Areas, Weights & Study Plan
2 Chapter 2: Accessing & Creating SAS Data Structures
2.1 SAS Environment, Syntax Rules, & Data Step Basics 2.2 SAS Data Libraries & the LIBNAME Statement 2.3 Investigating Libraries with PROC CONTENTS & PROC DATASETS 2.4 Importing Delimited & Excel Data with PROC IMPORT 2.5 Raw Data Ingestion with INFILE and INPUT Statements
3 Chapter 3: Managing & Combining SAS Data Sets
3.1 Reading SAS Data Sets with the SET Statement 3.2 Combining Data Sets: Concatenating & Interleaving 3.3 Match-Merging with BY Statements & FIRST./LAST. Processing 3.4 Controlling Data Output & Variable Selection (KEEP, DROP, RENAME, OBS=)
4 Chapter 4: Data Transformation & Conditional Logic
4.1 Creating & Modifying Variables with Assignment Statements 4.2 Modifying Variable Attributes with LENGTH, LABEL, FORMAT & RENAME= 4.3 Conditional Processing: IF-THEN/ELSE Statements & WHERE Subsetting 4.4 Accumulating Totals & Subtotals (RETAIN & Sum Statement) 4.5 Processing Data Iteratively with DO Loops
5 Chapter 5: SAS Functions & Data Type Conversions
5.1 Character Functions for String Manipulation 5.2 Numeric & Mathematical Functions 5.3 Working with SAS Dates, Times, & Intervals 5.4 Reading & Displaying Dates with Informats and Formats 5.5 Explicit & Implicit Data Type Conversions (INPUT & PUT)
6 Chapter 6: Restructuring Data & Program Maintenance
6.1 SAS Array Processing for Multi-Variable Transformations 6.2 Sorting Data Sets with PROC SORT 6.3 Restructuring Data Sets with PROC TRANSPOSE 6.4 Creating & Applying Custom Formats with PROC FORMAT 6.5 Simplifying Programs with Macro Variables (%LET)
7 Chapter 7: Error Handling & Debugging SAS Programs
7.1 SAS Log Analysis & Diagnostic Messages 7.2 Syntax vs. Logic Errors & Phasing 7.3 Debugging Techniques with _ERROR_, _N_, & PUT Statements 7.4 Identifying Logic Errors with the PUTLOG Statement 7.5 Handling Missing Values & Preventing Calculation Propagations
8 Chapter 8: Summary & Detail Data Reporting
8.1 Detail Reporting with PROC PRINT 8.2 Descriptive Statistics with PROC MEANS & PROC SUMMARY 8.3 Frequency & Categorical Analysis with PROC FREQ 8.4 Screening Extreme & Missing Values with PROC UNIVARIATE 8.5 Custom Tabular Reports with PROC REPORT & PROC TABULATE
9 Chapter 9: ODS Output Delivery & Data Export
9.1 Output Delivery System (ODS) Architecture Basics 9.2 Generating PDF, HTML, & RTF Output Destinations 9.3 Exporting Reports to Excel with ODS EXCEL & XLSX 9.4 Generating CSV, PowerPoint & Other ODS Destinations 9.5 Customizing ODS Titles, Footnotes, & Global Options 9.6 Exporting SAS Data Sets with PROC EXPORT & the XLSX Engine
5.2 Numeric & Mathematical Functions
Key Takeaways Explain This Topic AI
The SUM function calculates the sum of non-missing arguments, whereas the addition operator (+) returns a missing value if any operand is missing.
ROUND(argument, round-off-unit) rounds values to the nearest multiple of the specified unit, such as 0.01 for currency cents.
INT truncates decimal values toward zero, while FLOOR returns the greatest integer less than or equal to the argument and CEIL returns the smallest integer greater than or equal to the argument.
SAS statistical functions (MEAN, MIN, MAX, SUM, N, NMISS) automatically ignore missing values in their argument lists.
Variable list shortcuts in SAS functions require the OF keyword (e.g., SUM(OF x1-x10)) to prevent SAS from interpreting hyphens as subtraction operators.
Last updated: August 2026
5.2 Numeric & Mathematical Functions
Numeric processing is at the heart of SAS programming. Whether performing financial calculations, data transformations, or descriptive statistical analysis, SAS programmers rely on built-in numeric functions. A critical requirement for the SAS Base Certification exam is knowing how SAS numeric functions handle missing data, rounding precision, integer truncation, mathematical transformations, and variable list arguments.
1. Rounding and Truncation Functions
SAS provides several functions to round or truncate floating-point numbers into integers or specified decimal increments.
The ROUND Function
The ROUND function rounds a numeric value to the nearest multiple of a specified round-off unit.
Syntax: ROUND(argument, <round-off-unit>)
If round-off-unit is omitted, SAS rounds to the nearest integer (default unit = 1 ).
- If the argument is halfway between two multiples, SAS rounds up to the larger value. data work.round_demo;
- val1 = round(12.3456, 0.01); /* 12.35 (rounds to nearest hundredth) */
- val2 = round(12.3456, 0.1); /* 12.3 (rounds to nearest tenth) */
- val3 = round(12.3456); /* 12 (rounds to nearest integer) */
- val4 = round(148.50, 10); /* 150 (rounds to nearest ten) */
- run;
- Comparing INT , FLOOR , and CEIL
Understanding the differences between integer truncation functions is frequently tested on the SAS certification exam, especially when operating on negative numbers.
- Function Mathematical Definition Positive Example ( 3.7 ) Negative Example ( -3.7 )
- INT(x) Truncates decimal portion (rounds toward zero) 3 -3
- FLOOR(x) Greatest integer less than or equal to x 3 -4
- CEIL(x) Smallest integer greater than or equal to x 4 -3 data work.trunc_demo;
- pos = 5.8;
- neg = -5.8;
- int_pos = int(pos); /* 5 */
- floor_pos = floor(pos); /* 5 */
- ceil_pos = ceil(pos); /* 6 */
- int_neg = int(neg); /* -5 (truncates decimal) */
- floor_neg = floor(neg); /* -6 (rounds down away from zero) */
- ceil_neg = ceil(neg); /* -5 (rounds up toward zero) */
- run;
- 2. Advanced Mathematical Utility Functions ( MOD , SQRT , ABS , LOG )
In addition to rounding, Base SAS includes mathematical functions for algebra, remainder arithmetic, and absolute value calculations.
- The MOD Function (Remainder Division)
- MOD(n, d) returns the remainder when n is divided by d . data work.mod_demo;
- rem1 = mod(10, 3); /* Returns 1 (10 / 3 = 3 remainder 1) */
- rem2 = mod(14, 5); /* Returns 4 */
- run;
/* Exam Application: splitting even and odd observation numbers.
- Every data set written by OUTPUT must be named on the DATA statement. */
- data work.even_rows work.odd_rows;
- set work.transactions;
- if mod(_n_, 2) = 0 then output work.even_rows;
- else output work.odd_rows;
- run;
- Additional Mathematical Functions
ABS(x) : Returns the absolute (positive) value of x (e.g., ABS(-15) = 15 ).
SQRT(x) : Returns the square root of x . If x is negative, SAS returns a missing value ( . ) and prints an invalid argument note to the log.
LOG(x) / EXP(x) : Returns the natural logarithm or exponential power ( e x e^x e x ) of x .
SIGN(x) : Returns -1 if x < 0 , 0 if x = 0 , and 1 if x > 0 .
Order-Statistic and Random Functions Named in the Exam Content Guide
The official A00-231 content guide explicitly names SMALLEST , LARGEST , and RAND alongside SUM , MEAN , ROUND , and INT , so expect at least one item drawn from them.
SMALLEST(k, value-1, ..., value-n) : Returns the k -th smallest non-missing value from the argument list. SMALLEST(1, 40, ., 12, 75) returns 12 ; SMALLEST(2, 40, ., 12, 75) returns 40 .
LARGEST(k, value-1, ..., value-n) : Returns the k -th largest non-missing value. LARGEST(1, 40, ., 12, 75) returns 75 ; LARGEST(2, ...) returns 40 .
RAND('distribution', <parameters>) : Returns a random number from the named distribution. RAND('UNIFORM') returns a value in the interval (0, 1); RAND('NORMAL', 100, 15) returns a normal draw with mean 100 and standard deviation 15; RAND('INTEGER', 1, 6) simulates a die roll. data work.order_stats;
a = 40; b = .; c = 12; d = 75;
- low1 = smallest(1, a, b, c, d); /* 12 - missing values are skipped */
- low2 = smallest(2, a, b, c, d); /* 40 */
- high1 = largest(1, a, b, c, d); /* 75 */
- spread = high1 - low1; /* 63 */
- run;
- /* RAND requires a seed for reproducible streams */
- data work.simulated;
- call streaminit(20260807); /* fixes the random stream */
- do trial = 1 to 5;
- u = rand('UNIFORM');
- die = rand('INTEGER', 1, 6);
- output;
- end;
- run;
Exam Tip : SMALLEST(k, ...) and LARGEST(k, ...) take the rank first and the values afterwards, and both ignore missing values. RAND needs CALL STREAMINIT(seed); before the first call if the results must be reproducible; without it SAS seeds from the system clock.
3. Descriptive Statistics Functions & Missing Values
SAS DATA step functions can calculate summary statistics across variables within a single observation (row-wise processing).
Common statistical functions include:
SUM(arg1, arg2, ...) : Calculates the total of non-missing values.
MEAN(arg1, arg2, ...) : Calculates the arithmetic average of non-missing values.
MIN(arg1, arg2, ...) / MAX(arg1, arg2, ...) : Identifies the minimum or maximum non-missing value.
N(arg1, arg2, ...) : Counts the number of non-missing numeric values.
NMISS(arg1, arg2, ...) : Counts the number of missing numeric values.
STD(arg1, arg2, ...) / VAR(arg1, arg2, ...) : Computes the standard deviation or variance across row arguments.
Critical Difference: SUM Function vs. Addition Operator ( + )
One of the most important concepts in SAS programming is the handling of missing values ( . ) when performing arithmetic calculations. data work.missing_comparison;
- x = 10;
- y = .;
- z = 30;
- /* Using Addition Operator */
- total_op = x + y + z; /* Result: . (Missing!) */
- /* Using SUM Function */
- total_fn = sum(x, y, z); /* Result: 40 (Ignores missing value) */
- run;
Exam Rule : If any argument in an expression using the + operator is missing, SAS evaluates the entire expression as a missing value ( . ). In contrast, the SUM function ignores missing values and calculates the sum of all remaining valid numeric arguments. If all arguments passed to SUM are missing, SUM returns a missing value.
4. Using Variable Lists with the OF Keyword
When passing a list or range of variables to a SAS function, you must include the keyword OF before the variable list.
Variable List Syntax Types:
- Numbered Range : sum(of qtr1-qtr4) (expands to qtr1, qtr2, qtr3, qtr4 )
- Name Range : mean(of height--weight) (includes all variables between height and weight in dataset order)
- Name Prefix : max(of sales:) (includes all variables starting with the prefix sales )
- All Numeric : sum(of _numeric_) (includes all numeric variables in the dataset) data work.variable_lists;
- qtr1 = 100; qtr2 = 150; qtr3 = .; qtr4 = 200;
- /* Correct syntax using OF keyword */
- total_sales = sum(of qtr1-qtr4); /* Result: 450 */
- avg_sales = mean(of qtr1-qtr4); /* Result: 150 (450 / 3 valid values) */
- /* INCORRECT SYNTAX (Common Exam Trap!) */
- /* diff = sum(qtr1 - qtr4); */
- /* Without OF, SAS computes qtr1 minus qtr4 (100 - 200 = -100) and passes -100 to SUM! */
- run;
Critical Exam Pitfall : Omitting the OF keyword in sum(qtr1-qtr4) causes SAS to treat - as a subtraction operator rather than a range hyphen, yielding sum(100 - 200) = -100 instead of summing four variables!