BookmarkSubscribeRSS Feed
milts
Pyrite | Level 9
hi experts,

i'd like to check a variable if it is null or missing. if so, i'll assign the value 0 to another column, else the other column will just take it's value.

which between these two is more efficient?

case when var1 not is missing then var1 else 0 end as var2

OR

coalesce(var1,0) as var2

thanks,
milton
2 REPLIES 2
Cynthia_sas
Diamond | Level 26
Hi:
This might be one of those instances where "your mileage may vary" depending on the rest of your query and the size of the file(s) being accessed/created. Running some benchmarks might be in order.

A review of the doc might be in order too:
http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#/documentation/cdl/en...

I have to think there was -some- reason for this note in the doc:

Note: If your query contains a large number of COALESCE function calls, it might be more efficient to use a natural join instead. See Natural Joins.


cynthia
milts
Pyrite | Level 9
Thank you very much for the input Cynthia.

Milton

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1572 views
  • 0 likes
  • 2 in conversation