turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS Procedures
- /
- Array problem

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-25-2009 12:09 PM

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;

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to deleted_user

11-25-2009 12:46 PM

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

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

11-25-2009 02:17 PM

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;

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;