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
SAS Super FREQ
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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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