Avg of an array

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

Avg of an array

Dear All,

I need the average of 1000 values as the last column.

X       y1  y2 ... y1000                      AVG

a      [ 1000 simulations result]        Here is the avg of 1000 values

I have not even started the simulation, but I imagine I will use

array sim{1000} y;

Thank you.

- Matt


Accepted Solutions
Solution
‎08-13-2013 09:52 AM
Super Contributor
Posts: 644

Re: Avg of an array

You do not need an array

AVG = mean (of y1 -- y1000) ;

Richard

View solution in original post


All Replies
Solution
‎08-13-2013 09:52 AM
Super Contributor
Posts: 644

Re: Avg of an array

You do not need an array

AVG = mean (of y1 -- y1000) ;

Richard

Occasional Contributor
Posts: 14

Re: Avg of an array

Thanks Richard !!!

So if I use array, then is this correct?

AVG = mean(of sim{1} - sim{1000} );

Side question, what is the difference b/w one dash - and two dashes --   ?

Thanks.

- Matt

Super User
Posts: 5,085

Re: Avg of an array

Regarding the side question ...

A single dash would be preferred here.  It refers to the list of variables that have the same prefix, with a numeric suffix.

The double dash also refers to a list of variables, but the name pattern does not matter.  This is a legitimate list:

cat -- dog

It means all the variables in the data set, in the order in which they were created, starting with CAT and ending with DOG.  If you are not sure of the internal order of variables, PROC CONTENTS will tell you.  It can even print its report using the internal order rather than the alphabetical order.


Super Contributor
Posts: 644

Re: Avg of an array

The choice of a double dash in my response was deliberate, in case the O/P had simplified (as is often the case) the names of the variables and they were not a numerical sequence.  It would give exactly the same results unless for some reason another variable was created mid sequence, which in this instance seemed unlikely.

Richard

Trusted Advisor
Posts: 1,131

Re: Avg of an array

if we consider that there are variables like below

y1 y2 y3..............y1000

then we can take the average of all these variable in the below way

average=mean(of y1-y1000);

This way we will get the average of all the 1000 variables into one variable.

Thanks,

Jagadish

Thanks,
Jag
Trusted Advisor
Posts: 1,131

Re: Avg of an array

Another approach of using arrays to get the means of the variables is as below

array avg(*) y1-y1000;

average=mean(of avg(*));

Thanks,

jagadish

Thanks,
Jag
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 252 views
  • 4 likes
  • 4 in conversation