BookmarkSubscribeRSS Feed
OS2Rules
Obsidian | Level 7
Hi all:

I'm not great with macros but I have a problem. How do I correct a 'divide by zero' when the values in question are macro variables?

Here is a chunk of my code:

[pre]

proc sql;
select unique count(*) into :d_rec_count from worka;
select unique count(*) into :d_clo_count from worka where resolvedDT ne .;
select unique &d_clo_count/&d_rec_count into :d_clo_percent from worka;
quit;
run;

[/pre]

but when the divisor in the last 'select' is 0 (zero), I get a message 'No rows were selected' and the value of &d_clo_percent is incorrect.

I think what I need to do is check that the value of the divisor is zero and set d_clo_percent to 0 (zero) somehow.

Thanks in advance.
2 REPLIES 2
DBailey
Lapis Lazuli | Level 10
how about:

proc sql;
select sum(case when resolvedDT ne . then 1 else 0 end) / count(*)
from worka;
quit;
Cynthia_sas
Diamond | Level 26
And, the DIVIDE function was designed to allow divide by zero without issuing that error message:
http://support.sas.com/kb/19/965.html

cynthia

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1607 views
  • 0 likes
  • 3 in conversation