Help using Base SAS procedures

Array problem

Reply
N/A
Posts: 0

Array problem

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;
Super Contributor
Super Contributor
Posts: 3,174

Re: Array problem

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
Super Contributor
Posts: 359

Re: Array problem

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;
Ask a Question
Discussion stats
  • 2 replies
  • 109 views
  • 0 likes
  • 3 in conversation