BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sousimou
Calcite | Level 5

Hi,

 

Can someone help me in a short sas program to simulate sample variace distribution.

my assumptions are taken from a Normal Sample (N=50, mean =0.01284, var=0.01797).

 

thank you

sousimou

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

Read the article "Simulation in SAS: The slow way or the BY way" for the basic approach and important ideas. Then modify the second program to use the variance instead of the mean.  It should look like this:

 

/* efficient simulation that calls a SAS procedure */
%let N = 50;
%let NumSamples = 1000;
data Sim(keep=SampleID x); 
do SampleID = 1 to &NumSamples;  /* 1. create many samples */
   do i = 1 to &N;               /* sample of size &N */
      x = rand("Normal", 0.01284, sqrt(0.01797)); /* RAND uses StdDev, not Variance */
      output;
   end;
end;
run;
 
proc means data=Sim noprint; 
   by SampleID;                  /* 2. compute many statistics */
   var x;
   output out=OutStats var=SampleVar;
run;
 
/* 3. analyze the sampling distribution of the statistic */
proc univariate data=OutStats;
   var SampleVar;
   histogram SampleVar / odstitle="Sampling Distribution of Variance"
             href=0.01797;
run;

 

View solution in original post

4 REPLIES 4
Ksharp
Super User

Check function RAND().

Calling @Rick_SAS

Rick_SAS
SAS Super FREQ

Do you want to do this in Base SAS (DATA step and PROC MEANS) or are you planning to do this in SAS/IML?

 

Rick_SAS
SAS Super FREQ

Read the article "Simulation in SAS: The slow way or the BY way" for the basic approach and important ideas. Then modify the second program to use the variance instead of the mean.  It should look like this:

 

/* efficient simulation that calls a SAS procedure */
%let N = 50;
%let NumSamples = 1000;
data Sim(keep=SampleID x); 
do SampleID = 1 to &NumSamples;  /* 1. create many samples */
   do i = 1 to &N;               /* sample of size &N */
      x = rand("Normal", 0.01284, sqrt(0.01797)); /* RAND uses StdDev, not Variance */
      output;
   end;
end;
run;
 
proc means data=Sim noprint; 
   by SampleID;                  /* 2. compute many statistics */
   var x;
   output out=OutStats var=SampleVar;
run;
 
/* 3. analyze the sampling distribution of the statistic */
proc univariate data=OutStats;
   var SampleVar;
   histogram SampleVar / odstitle="Sampling Distribution of Variance"
             href=0.01797;
run;

 

sousimou
Calcite | Level 5

thank you all for your contribution.

The SAS code proposed by Rick is what I was looking for. 

 

thank you Rick

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1380 views
  • 1 like
  • 3 in conversation