BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have a data set that has 1 variable (numbers) and 100 observations(100 rows)
I want to randomly pick 10 variables out of the hundred with replacement
put them in an array
now I want to do it again 10 times and put them in the dataset with array 1-10

then I want to calculate the mean for the 10 columns in the array.
I don't get errors when I run my code, but I also don't get any observations
Any help would be greatly appreciated. THANKS!

Here is my code:


DATA sample;
array All {10,10}; /*two dimensional arrays 10 x 10 */
do k= 1 to 10; /*start do loop to read 10 times*/
all(i,k)=0;

choose=int(ranuni(58)*m)+1; /*generate 10 random observations out of data*/
set work.data point=choose nobs=m;
i+1;
if i > 10 then stop;

all(i,k)= numbers;

end;
average=mean(of k1-k10);
drop i k;
run;
2 REPLIES 2
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
You have a STOP statement inside your DO / END loop, which prematurely stops the DATA step execution before the DATA step gets to the MEAN calculation. You must determine where to execute an explicit OUTPUT for your purposes and when (how many times).

Suggest you enhance your program debugging capabilities by using the line below liberally in various locations to learn what SAS is performing (substituting DIAGn for DIAG1 with each location where you add the line):

PUTLOG '>DIAG1>' / _ALL;

Scott Barry
SBBWorks, Inc.


SAS Language Reference: Concepts, DATA Step Processing
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a001281588.htm
Flip
Fluorite | Level 6
This fixes a few of the problems.

DATA sample;
m = 1;
array All {10,10}; /*two dimensional arrays 10 x 10 */
i=1;
do k= 1 to 10; /*start do loop to read 10 times*/
do i = 1 to 10;
all(i,k)=0;
choose=int(ranuni(58)*m)+1; /*generate 10 random observations out of data*/
put choose =;
set work.data point=choose nobs=m ;

all(i,k)= numbers;
put numbers= i = k=;
end;
end;
do j = 1 to 10;
average=mean(of all(j,1), all(j,2),all(j,3),all(j,4),
all(j,5),all(j,6),all(j,7),all(j,8),all(j,9), all(j,10));
put average=;
output;
end;
stop;
*drop i k;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 919 views
  • 0 likes
  • 3 in conversation