BookmarkSubscribeRSS Feed
podarum
Quartz | Level 8

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

3 REPLIES 3
podarum
Quartz | Level 8

I think I got it.. using:

avg=Mean(of x y z);

Reeza
Super User

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)

Astounding
PROC Star

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 17696 views
  • 0 likes
  • 3 in conversation