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
- /
- Question on arithmetic conversion

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

11-24-2016 03:43 AM

Hello,

I am pretty new to SAS but I hve to maintain some older programs. Now I am stuck with a problem.

I have a program that does this:

PROC MEANS NOPRINT;

VAR AMOUNT AVG1 AVG2;

BY OBJNAME;

OUTPUT OUT=WORK.SUMM1

SUM(AMOUNT) = AMOUNT

MEAN(AVG1 AVG2) =

AVG1 AVG2 ;

Sadly the input data of AVG1 and AVG2 is not an average at all but the cumulated data, so to get real averages at the end I would have to do sum up AVG1 and AVG2 for each OBJNAME and divide it by AMOUNT.

If I do

PROC MEANS NOPRINT;

VAR AMOUNT AVG1 AVG2;

BY OBJNAME;

OUTPUT OUT=WORK.SUMM1

SUM(AMOUNT) = AMOUNT

SUM(AVG1 AVG2) =

AVG1 AVG2 ;

it looks nice but I still need the division, my idea was putting in something like

AVG1= AVG1/AMOUNT

but I didn't find a way how this could work.

Maybe someone van give me a hint how to do this?

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

11-24-2016 04:11 AM

```
data summ1;
set dataset (rename=(
amount=oldamount
avg1=oldavg1
avg2=oldavg2
));
by objname;
if first.objname
then do;
amount = 0;
avg1 = 0;
avg2 = 0;
end;
amount + oldamount;
avg1 + oldavg1;
avg2 + oldavg2;
if last.objname
then do;
avg1 = avg1 / amount;
avg2 = avg2 / amount;
output;
end;
drop oldamount oldavg1 oldavg2;
run;
```

"Manual" solution.

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

Maxims of Maximally Efficient SAS Programmers

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

11-24-2016 04:50 AM

I will have to check this, as I am not shure wether it will no confuse with my data step.

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

11-24-2016 04:53 AM

Unless you make use of the auomatically created _type_ and _freq_ variables, you should get the right output.

---------------------------------------------------------------------------------------------

Maxims of Maximally Efficient SAS Programmers

Maxims of Maximally Efficient SAS Programmers