## Avg of an array

Solved
Occasional Contributor
Posts: 14

# 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

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

Posted in reply to RichardinOz

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: 6,781

## 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

Posted in reply to Astounding

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

Posts: 1,147

## 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,

Thanks,
Jag
Posts: 1,147

## 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,