DATA Step, Macro, Functions and more

Macro Divide by Zero

Reply
Super Contributor
Posts: 358

Macro Divide by Zero

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.
Super Contributor
Posts: 578

Re: Macro Divide by Zero

how about:

proc sql;
select sum(case when resolvedDT ne . then 1 else 0 end) / count(*)
from worka;
quit;
SAS Super FREQ
Posts: 8,742

Re: Macro Divide by Zero

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
Ask a Question
Discussion stats
  • 2 replies
  • 235 views
  • 0 likes
  • 3 in conversation