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
SAS Super FREQ
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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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