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
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;
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;
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!
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.