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

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!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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