BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
MattLin
Calcite | Level 5

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
RichardinOz
Quartz | Level 8

You do not need an array

AVG = mean (of y1 -- y1000) ;

Richard

View solution in original post

6 REPLIES 6
RichardinOz
Quartz | Level 8

You do not need an array

AVG = mean (of y1 -- y1000) ;

Richard

MattLin
Calcite | Level 5

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

Astounding
PROC Star

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.


RichardinOz
Quartz | Level 8

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

Jagadishkatam
Amethyst | Level 16

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

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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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