Calcite | Level 5

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

1 ACCEPTED SOLUTION

Accepted Solutions
Quartz | Level 8

## Re: Avg of an array

You do not need an array

AVG = mean (of y1 -- y1000) ;

Richard

6 REPLIES 6
Quartz | Level 8

## Re: Avg of an array

You do not need an array

AVG = mean (of y1 -- y1000) ;

Richard

Calcite | Level 5

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

PROC Star

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

Quartz | Level 8

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

Amethyst | Level 16

## 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
Amethyst | Level 16

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