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
You do not need an array
AVG = mean (of y1 -- y1000) ;
Richard
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
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.
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
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
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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.