BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
cdw04
Calcite | Level 5

Hi There,

 

New to SAS coding so if you need more details please let me know

 

I am getting the following error when to running a code is EG 4.3

 

ERROR: CLI open cursor error: ERROR:  Divide by 0 

 

Sample of data set

 

 ID   Card_Sales   Card_Used

001  25                5

002  10                8

003  7                  2

004  0                  0

 

SAS Code I am using:

 

Card_Used / Card_Sale as Ratio

 

Any assistance would be greatly appreicated.

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
DanZ
Obsidian | Level 7
data want;
set have;
if card_sales in (0,.) then ratio = 0;
else ratio = card_used/card_sales;
run;

View solution in original post

4 REPLIES 4
Astounding
PROC Star

If you were working in a DATA step, the best way would be to use an IF/THEN statement:

 

if Card_Sale then Ratio = Card_Used / Card_Sale;

 

That would skip the processing when Card_Sale is either zero or missing.  Since it looks like you are working with SQL instead, you would need to add a CASE statement to assign Ratio a missing value when Card_Sale is zero or missing.

DanZ
Obsidian | Level 7
data want;
set have;
if card_sales in (0,.) then ratio = 0;
else ratio = card_used/card_sales;
run;
Rick_SAS
SAS Super FREQ

You should set ratio=. (missing value) if the denominator is invalid.  Using zero is not correct.

Ksharp
Super User

Use function  DIVIDE().

ratio =divide( card_used,card_sales) ;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 4 replies
  • 10963 views
  • 5 likes
  • 5 in conversation