Hello,
I am new to SAS and would like to accomplish the following task: the first one creates 100 variables, the second code piece takes the average of the 100 values (call this variable A1).
My question: I wish to repeat this 2000 times, so that I have a dataset of 2000 observations of A1, but I don't know how to modify the code...
Thanks!!
data rand;
call streaminit(-1);
do i = 1 to 100;
x = rand("Normal")*5+1;
output;
end;
run;
proc means noprint data=rand;
output out=rand (drop=_type_ _freq_)
mean(x)=A1; run;
First off, If you are taking mean(X), how can you expect 2000 values(observations) in your output A1 of proc means step. Please clarify
Did you mean -
data rand;
call streaminit(-1);
do j=1 to 2000; /*modified here, is this what you want?*/
do i = 1 to 100;
x = rand("Normal")*5+1;
output;
end;
run;
proc means noprint data=rand;
output out=rand (drop=_type_ _freq_)
mean(x)=A1; run;
Thanks,
Naveen
Hi
First thing, i did not understand the clear objective of your question. If you can give expected dataset example, it will be very much helpful.
However, as you said you are new to SAS, following is what i presume you want to do:
data new;
set rand;
do i = 1 to 2000;
output;
end;
drop i;
run;
First off, If you are taking mean(X), how can you expect 2000 values(observations) in your output A1 of proc means step. Please clarify
Did you mean -
data rand;
call streaminit(-1);
do j=1 to 2000; /*modified here, is this what you want?*/
do i = 1 to 100;
x = rand("Normal")*5+1;
output;
end;
run;
proc means noprint data=rand;
output out=rand (drop=_type_ _freq_)
mean(x)=A1; run;
Thanks,
Naveen
Dear Naveen,
Thank you for the help. The first part (generating 2000 sets of 100 random values) is what I need, and I was able to solve the second part. In short, the final code would look like:
data rand;
call streaminit(-1);
do j=1 to 2000; /*modified here*/
do i = 1 to 100;
x = rand("Normal")*5+1;
output;
end;
end; /*modified here*/
run;
proc means noprint data=rand;
by j; /*modified here*/
output out=Rand_means (drop=_type_ _freq_) /*modified here*/
mean(x)=A1; run;
Kevin
Hi,
It rather looks much too simple and so I'm afraid perhaps my understanding could be wrong somewhere wrong. Is this what you really want?
data rand;
call streaminit(-1);
do j=1 to 2000; /*modified here*/
do i = 1 to 100;
x = rand("Normal")*5+1;
output;
end;
end;
drop i; /*modified here*/
run;
Proc sql;
Create table Rand_means as
Select
j, mean(x) as A1
from rand
group by j;
quit;
Please correct my understanding. Thanks.
Merry Christmas,
Naveen
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Select SAS Training centers are offering in-person courses. View upcoming courses for: