Help using Base SAS procedures

mean across variables

Reply
Super Contributor
Posts: 395

mean across variables

Hi,  Is there a way SAS allows to do a mean across varaibles (and use a BY statement).

Here's what I mean:

HAVE:

Prod   Price1  Price2  Price3  Price4

A          2          4          7         6
B          3          .           5        3

C          .          5          .         .

D          .           .           .         .

WANT:   If I want the MEAN of the last 3 Prices & last 4 Prices

Prod   Month3_Prices         Month4_Prices

A                5.6                            4.7
B                 4                              3.6

C                 5                                5

D                 .                                .      

I tried different variations of Proc MEAN, couldn't get it, but I'm sure there is a simple way.

Thanks

Super Contributor
Posts: 395

Re: mean across variables

I think I got it.. using:

avg=Mean(of x y z);

Super User
Posts: 17,784

Re: mean across variables

Yes, except you can do mean(of price1--price3)  and mean (of price1--price4) as well as mean(price1, price2, price3)  and mean(price1, price2, price3, price4)

Super User
Posts: 5,081

Re: mean across variables

Well, it may not be everyone's idea of fun, but here's a program you can play around with ... "just for fun".

data _null_;

p1=1;

p3=3;

p2=4;

of=20;

m1 = mean(of p1--p3);

m2 = mean(of p1-p3);

m3 = mean(of p1 p2 p3);

m4 = mean(of p1,p2,p3);

m5 = mean(of,p1,p2,p3);

put m1= m2= m3= m4= m5=;

run;

Ask a Question
Discussion stats
  • 3 replies
  • 6672 views
  • 0 likes
  • 3 in conversation