Code: coalesce(argument1,….argumentn)
If you have two columns with the same details but in one column there are missing values and in other, there are non-missing values at some places and vice-versa, then coalesce function returns the value of the first nonmissing argument. This can also be taken from another table column by simple joins.
For example, in the table below, I extracted the data which has missing account ID.
irstName | LastName | Income | AccountID | DateTime | MerchantID | Amount |
---|---|---|---|---|---|---|
. | . | 07MAY18:15:35:02 | 542058 | 58.79 | ||
Gary | Sienkiewicz | 67210.91 | 1010159565 | 16SEP18:14:57:08 | 568268 | 107.16 |
. | . | 24FEB18:17:27:42 | 562326 | 370.53 | ||
Sergio | Lefeld | 86859.07 | 1010367330 | 17OCT18:11:02:38 | 525576 | 21.02 |
Sergio | Lefeld | 86859.07 | 1010367330 | 15MAY18:17:54:21 | 542058 | 23.39 |
. | . | 18OCT18:17:52:51 | 549940 | 37.24 | ||
John | Oliver | 43623.75 | 2020012887 | 23FEB18:09:25:37 | 525576 | 108.22 |
Iva | Bower | 67949.96 | 3030085224 | 27JUL18:12:05:48 | 525576 | 26.1 |
Janet | Sienkiewicz | 50111.59 | 3030101942 | 18SEP18:12:13:40 | 549940 | 37.38 |
Olga | Comstock | 31896.96 | 3030165207 | 11MAR18:10:07:14 | 580881 | 319.95 |
. | . | 13FEB18:16:48:05 | 513178 | 115.48 | ||
. | . | 27JAN18:13:52:35 | 536123 | 1.76 | ||
Ada | Vieyra | 29586.44 | 4040164206 | . | . | . |
Samantha | Carney | 25476.14 | 5540174271 | . | . | . |
But the other table has account ID information as well and this other table has missing account ID too. So can we combine account ID such that we have full list of Account ID with non missing information?
Yes, this is possible.
with this code:
proc sql; select FirstName, LastName, Income, coalesce(c.AccountID,t.AccountID) as AccountID format=10., DateTime, MerchantID, Amount from sq.smallcustomer as c full join sq.smalltransaction as t on c.AccountID = t.AccountID; quit;
Until next time, if you want to learn SAS by an expert and become a Quant developer, reach out to us at [email protected]
Keep Learning and Take Care <3
Top site ,.. amazaing post ! Just keep the work on !