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
- /
- Base SAS Programming
- /
- Recreate a sum(var)/sum(var) from proc sql into so...

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

06-17-2016 02:26 PM

Hi,

I inherited this code:

proc sql;

create table junk.k5_sex_2003 as

select sex, 2003 as year, (sum(payamt) / sum(yar)) as value

from junk.py_2003b (where=(mod1 in (1 2 3 4)))

group by sex.;

quit;

And i don't think it's working right, so i'd like to recreate it in something else, but i don't know enough about proc means/tabulate/summary to do it.

The only part i want to double check is:

(sum(payamt) / sum(yar)) as value,

by var

What's the best way to do this calculation another way other than proc sql? There are way too many records to do it by hand.

Thanks

Megan

Accepted Solutions

Solution

06-17-2016
02:35 PM

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

Posted in reply to MeganE

06-17-2016 02:31 PM

Here's the proc means code, which will create the sum variables and then you'll need to do the division by hand or another data step.

```
proc means data=junk.py_2003b sum nway;
where mod1 in (1 2 3 4);
class sex;
var payamt yar;
output out=totals sum(payamt yar) = tot_payamt tot_var;
run;
data check_value;
set totals;
value = tot_payamt/tot_var;
run;
```

All Replies

Solution

06-17-2016
02:35 PM

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

Posted in reply to MeganE

06-17-2016 02:31 PM

Here's the proc means code, which will create the sum variables and then you'll need to do the division by hand or another data step.

```
proc means data=junk.py_2003b sum nway;
where mod1 in (1 2 3 4);
class sex;
var payamt yar;
output out=totals sum(payamt yar) = tot_payamt tot_var;
run;
data check_value;
set totals;
value = tot_payamt/tot_var;
run;
```

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

Posted in reply to Reeza

06-17-2016 02:36 PM

Thanks! Gave me the exact same numbers. Guess it was working, lol.