## Arithmetic in SAS

Frequent Contributor
Posts: 88

# Arithmetic in SAS

I need to calculate an OVERALL rate or percentage for my dataset. This involves (summing variable A)/(summing variable B and C).

I have already created new variables:

sum_a

sum_bc

Now what I want to do is sum_a/sum_bc

However, I don't want to have to create a new variable to do this. I just want to do sum_a/sum_bc. Is there any way to do this? Proc Print? I can't figure it out.

Super User
Posts: 23,771

## Re: Arithmetic in SAS

Depends a bit on where you want this value to be displayed.

You can look into the calculated option for proc report

Frequent Contributor
Posts: 88

## Re: Arithmetic in SAS

I don't eally care where it display, I just want to be able to see the value that it calculates.

I actually also realized that my summing did not work!

How do I sum one entire variable?

this is my code in my data step:

```sum_count_nscx=sum(count_nscx);
sum_denominator=sum(denominator);```
Super User
Posts: 23,771

## Re: Arithmetic in SAS

Here's one way:

``````proc means data=sashelp.shoes noprint;
output out=want sum(sales inventory returns)=/autolabel;
run;

title 'Summary of totals';
proc print;run;

title 'via data step';
data output;
set want;
calc = sales / (inventory + returns);
run;

proc print data=output;
format calc percent12.2;
run;

title 'via proc sql';
proc sql;
select sales / sum(inventory, returns) as Percent format=percent12.2
from want;
quit;``````
Posts: 1,837

## Re: Arithmetic in SAS

Try the next code:

Proc sql;

select rate as (sum_a / sum_bc)

from ... /* your input data set */

; quit;

the RATE will printed to output;

Posts: 1,837

## Re: Arithmetic in SAS

You can do it by:

Proc sql;

select rate as (sum(count_nscx) / sum(denominator))

from ... /* your input data set */

; quit;

Discussion stats
• 5 replies
• 389 views
• 4 likes
• 3 in conversation