SAS | COALESCE Function with Examples Last Updated : 30 Jul, 2019 Summarize Comments Improve Suggest changes Share Like Article Like Report The COALESCE function is employed to pick the first non-missing value in a list of variables. In other words, it returns the first non-blank value of each row. Let's produce a sample dataset in SAS to know how COALESCE perform. Example: SQL data temp; input roll_no a1-a4; cards;12 . 98 52 . 23 79 . 67 . 14 90 82 88 85 ;run; Output: COALESCE : First Non-Missing Value SQL data exam; set temp; first_non_miss_val = coalesce(of a1 - a4); run; If you examine the output shown within the image below, you'd realize COALESCE returns 98 in first observation which is the first non-missing value among a1 = ., a2 = 98, a3 = 52, a4 =. COALESCE : Last Non-Missing Value Let us suppose you want to find out last non-missing value instead of first. For that, there is no such function available which will return last non-missing value but to achieve that we can reverse the list of variables and calculate the first non-missing value which would be equivalent to last non-missing value. Indirectly, we are considering to evaluate variables from right to left instead of left to right. SQL data exam; set temp; last_non_miss_val = coalesce(of a4-a1); run; Output: Note: coalesce(of a4-a1) is equivalent to coalesce(a4, a3, a2, a1). Comment More infoAdvertise with us Next Article How to import data into SAS? S ShubhamMaurya3 Follow Improve Article Tags : Software Engineering SAS Programming Similar Reads SAS | COMPRESS Function with Examples COMPRESS function is basically used to compress/removes all the spaces/blanks in a character string. In other words, it removes leading, between and trailing spaces from the strings. The COMPRESS function allows null arguments. A null argument is treated as a string that features a length of zero. E 2 min read How to create a function in MATLAB ? A function is a block of statements that intend to perform a specific task. Functions allow the users to reuse the code frequently. MATLAB has several predefined functions which are ready to use such as sin(), fact(), cos() etc. MATLAB also allows the users to define their own functions. Syntax: fun 2 min read SAS | Delete Empty Rows Generally, when we import data from external sources such as Excel/CSV files, it loads additional rows that are totally blank. Sometimes empty values in the database also affect the desired output so it's necessary to check missing cases and perform operations accordingly Example: Input: The sample 2 min read How to import data into SAS? Entering Data Directly: You can enter numbers of lines of data directly in SAS program by using a DATALINES statement. The keywords are as follows: DATA: The DATA step always starts with a DATA statement. The purpose of the DATA statement is to tell SAS that you are creating a new data set i.e. outd 3 min read SAS | How to read character using Ampersand(&) We can use ampersand (&) to notify SAS to read the variable until there are two or more spaces encounter as a delimiter. This technique is always useful when the variable contains two or more words. For example: Actual Input: "Geeks for Geeks" Expected Input: "GeeksforGeeks" Example 1: There are 1 min read SAS : How to Display Current Date? The today() function of SAS programming is basically used to generate current date. The format() function is used to display the format of the date in the specified format. In DD-MMM-YYYY format: Example: SQL data _null_; dt=today(); format dt yymmdd10.; put dt ; run; Output: In DDMMMYYYY format: Ex 1 min read Like