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
- /
- Need Two-Dimensional Array Help

- 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

04-05-2013 04:50 PM

Hello Everyone,

So I received a bit of a project from my stats professor.

I need to create a two-dimensional array where there are 1000 observations and 50 columns where I am generating random Poisson numbers with a seed of 0 and a lambda=3.

I came up with the following code:

data test2;

array p{2,50} p1c1-p1c50

p2c1-p2c50;

do j=1 to 2 by 1;

do i=1 to 50 by 1;

p[j,i]=ranpoi(0,3);

end;

end;

run;

This is my test code so far, and what my problem is that the observations are not separating out into individual rows.

It has been a while since I have played with arrays, so either my code is correct and when I do proc print my data that it is all going to be under one observation anyways or there is a way to break these out to where there are separate rows for each observation.

I would like to have separate rows so I can perform calculations on the proportion of 0s and 1s that appear in each observation.

Could someone please let me know where I am going wrong with this code?

Thanks!

Alisa

Message was edited by: Alisa Arnold So after having a light blub moment as I was walking out of school, this is what I have come up with: data tested; array pi{2,50} p1-p50 p1-p50; do i=1 to 2; do j=1 to 50; pi[i,j]=ranpoi(0,3); end; output; end; drop i j; run; proc print data=tested; run; I am hoping there is something easier I can do because I do not want to have to index p1-p50 1000 times in order to get this code to display the way I want it to. Thanks! Alisa

Accepted Solutions

Solution

04-05-2013
05:43 PM

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

04-05-2013 05:43 PM

Where you place an OUTPUT statement will affect the observations.

Are you sure you need a two dimension array? To get 1000 obs with 50 columns I would try

data test2;

array p p1c1-p1c50

;

do i = 1 to 1000;

do j=1 to 50 ;

p

end;

output;

end;

run;

All Replies

Solution

04-05-2013
05:43 PM

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

04-05-2013 05:43 PM

Where you place an OUTPUT statement will affect the observations.

Are you sure you need a two dimension array? To get 1000 obs with 50 columns I would try

data test2;

array p p1c1-p1c50

;

do i = 1 to 1000;

do j=1 to 50 ;

p

end;

output;

end;

run;

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

04-05-2013 06:11 PM

Thanks! I had my 'Why didn't I put an output in my DO loop?' thought as I was leaving school.

This does come out exactly how I want it to. Now it is off to do some calculations with all of this lovely data.

Thanks so much for your help!