Help using Base SAS procedures

Need Two-Dimensional Array Help

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 90
Accepted Solution

Need Two-Dimensional Array Help

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
Super User
Posts: 10,500

Re: Need Two-Dimensional Array Help

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=ranpoi(0,3);

  end;

  output;

  end;

  run;

View solution in original post


All Replies
Solution
‎04-05-2013 05:43 PM
Super User
Posts: 10,500

Re: Need Two-Dimensional Array Help

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=ranpoi(0,3);

  end;

  output;

  end;

  run;

Frequent Contributor
Posts: 90

Re: Need Two-Dimensional Array Help

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. Smiley Happy

Thanks so much for your help!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 120 views
  • 0 likes
  • 2 in conversation