turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- General Programming
- /
- Arithmetic in SAS

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

08-31-2016 02:29 PM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to christinagting0

08-31-2016 02:42 PM

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

You can look into the calculated option for proc report

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Reeza

08-31-2016 02:47 PM

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);

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to christinagting0

08-31-2016 04:42 PM

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;
```

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to christinagting0

08-31-2016 02:45 PM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Shmuel

08-31-2016 02:52 PM

I have just now seen your answer to Reeza.

You can do it by:

Proc sql;

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

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

; quit;