*The resulting variable has a length of 200. To avoid any data truncation, the length of the output variable needs to be set ahead of the function call. As a consequence, if one of the arguments has a length above 200 characters, the result may be truncated. It is important to note that if the coalescec function returns a value to a variable that has not previously been assigned a length, then that variable is given a length of 200 bytes. It performs a similar functionality for character arguments. *create and populate a string which has a size greater than 200 Ĭharacter_to_append = '). All the examples will be driven from the following base table: %let c_long_var_length = 300 This article is therefore intended to review the behavior of the various coealesce functions in SAS, and to outline the hurdles when using these functions. Simply switching to the character-compatible function, coalescec, may still have some side-effects as we will demonstrate in the following sections. If such a conversion fails, a null value will be passed to the function. More specifically, if column1 and column2 are characters, the automatic SAS conversion kicks in by trying to convert these values to numerics. The intuitive approach would be to simply rewrite the code as follows: data foo2 Ĭoalesce_column = coalesce(colum1, column2) Īlthough this approach seems to be correct at first glance, it may cause a potential issue: the coalesce function in the context of a data step treats parameters as numeric values. Select coalesce(colum1, column2) as coalesce_column Suppose, for example, that the following piece of code needs to be modified into a data step: proc sql These differences are important to acknowledge, especially when the code is migrated from PROC SQL to a data step. In SAS, the behavior of each of the coalesce functions depends on the processing context, either in a data step or in a PROC SQL statement. Coalescing refers to the process of checking the value of each input parameter in the order in which they are listed and returns the first non-missing value.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |