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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
NaveenSrinivasan
Calcite | Level 5

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

View solution in original post

4 REPLIES 4
JatinBansal
Calcite | Level 5

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;

NaveenSrinivasan
Calcite | Level 5

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

jassman1982
Calcite | Level 5

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

NaveenSrinivasan
Calcite | Level 5

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 947 views
  • 3 likes
  • 3 in conversation