SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
GN0001
Barite | Level 11

Hello team,

Proc SQL;
select b.this, a.this, 
case
When b.rate <0.25 Then (somenum/b.rate)

b.rate is equal 0, then we have divide by zero. This produces errors in Excel and is handled by IfError.

What is the equal of IFError is in SAS?

respectfully,

Blue blue

Blue Blue
3 REPLIES 3
PaigeMiller
Diamond | Level 26
case when b.rate>0 and b.rate <0.25 then (somenum/b.rate)

This will not produce an error in SAS, but the resulting variable is still missing in SAS.

 

You can also do this:

 

case when b.rate <0.25 then divide(somenum,b.rate)

which also gives a missing, but no error.

--
Paige Miller
KatScott
Fluorite | Level 6

The following will replicate the same behavior as IFERROR.

Proc SQL;
select b.this, a.this, 
case
When b.rate <0.25 Then coalesce(somenum/b.rate.0) 

For more information please see:

Function documentation:


https://go.documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/sqlproc/p1gdr5t7sd3g3qn1d7fg23zuwzml.htm#!


An example:
https://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002473712.htm

 

Best,

K

KatScott
Fluorite | Level 6
One correction I needed a comma:

Proc SQL;
select b.this, a.this,
case
When b.rate <0.25 Then coalesce(somenum/b.rate,0)

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 3 replies
  • 2068 views
  • 3 likes
  • 3 in conversation