BookmarkSubscribeRSS Feed
wetzer123
Calcite | Level 5

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?

3 REPLIES 3
Kurt_Bremser
Super User
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.

wetzer123
Calcite | Level 5

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

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 3 replies
  • 708 views
  • 0 likes
  • 2 in conversation