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
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;
Check function RAND().
Calling @Rick_SAS
Do you want to do this in Base SAS (DATA step and PROC MEANS) or are you planning to do this in SAS/IML?
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;
thank you all for your contribution.
The SAS code proposed by Rick is what I was looking for.
thank you Rick
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!
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.