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.
- COALESCE : First Non-Missing Value
a1 - a4);
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.
Note: coalesce(of a4-a1) is equivalent to coalesce(a4, a3, a2, a1).
- SAS | COMPRESS Function with Examples
- How to import data into SAS?
- Introduction to SAS programming
- How to import External Data from Excel or Text file into SAS Programming?
- How to Create or Modify a Variable in SAS Programming?
- Contains and Between-And operators in SAS Programming
- How to drop variables from a dataset in SAS Programming?
- Where Statement in SAS Programming
- If-Then-Else statement in SAS Programming
- IS MISSING and IS NOT MISSING Operators in SAS Programming
- Like Operator in SAS Programming
- SAS | How to specify a list of Variables?
- SAS | How to read character of varying length using COLON Modifier
- SAS | How to read character using Ampersand(&)
- SAS | Date Formats and Informats
- SAS | Delete Empty Rows
- SAS : How to Display Current Date?
- Beep() function in C with Examples
- Java Swing | JSplitPane with Examples
- Java Swing | JComboBox with examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.