BookmarkSubscribeRSS Feed
fibonacheese
Calcite | Level 5

Hi, I am not sure how to get started on this question:

 

  1. Generate 2000 samples of size 40000 random numbers from a Poisson distribution with lambda = 8. For each of these 2000 samples calculate the mean.

so far I have 

 

data poisson;
call streaminit (0);
psamples = 2000;
psizesamp = 40000;
lambda = 8;
do psample = 1 to psamples;


      do n2 = 1 to psizesamp;

 

      end;

 

end;

 

I understand that I will need to use a nested loop, but I do not know how to set up poisson distribution. I imagine it is somewhat similar to uniform distribution. Anyone know how I would do that or any resources to look at! Thank you

2 REPLIES 2
PGStats
Opal | Level 21

Get a random Poisson value with:

 

x = rand("Poisson", lambda);

PG
KachiM
Rhodochrosite | Level 12

@fibonacheese 

 

As indicated by @PGStats  try the following:

 

data poisson;
   call streaminit (0);
   retain sumy meantotal;
   psamples = 20; *2000;
   psizesamp = 40000;
   lambda = 8;
   do psample = 1 to psamples;
      sumy = 0;
      do n2 = 0 to psizesamp;
         y = rand("Poisson", lambda);
         sumy + y;
      end; 
      mean = sumy / psizesamp;
      meantotal + mean;
      *output;
   end;
   mom = meantotal / psamples;
   put 'Mean of the Means ' mom;
run;

See the commented statements for lesser / no output. A better way is to keep out the initial values as macro variables for not to load them into PDV as:


%let lambda = 8;
%let psamples = 2000;
%let psizesamp = 40000;

 

and inserting them into the code.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 651 views
  • 0 likes
  • 3 in conversation