Any one know how to simulate a dataset by given parameters below:
Given parameters: mean=0.195, max=0.26, min=0.13,
Request: random generate a 8 observation dataset with normal distribution.
I try to use rand, but it sounds no option for max and min
data sixnum;
do i=1 to 6;
random=rand("normal", mean, STDDEV );
output;
end;
run;
Thanks
You can calculated P value for MIN and MAX value(take them as percentile).
After that ,sample from PValue_MIN and PValue_MAX , mapping these P value back to percentile.
Check @Rick_SAS 's blog
https://blogs.sas.com/content/iml/2013/07/24/the-truncated-normal-in-sas.html
/*
You can calculated P value for MIN and MAX value(take them as percentile).
After that ,sample from PValue_MIN and PValue_MAX , mapping these P value back to percentile.
Check @Rick_SAS 's blog
https://blogs.sas.com/content/iml/2013/07/24/the-truncated-normal-in-sas.html
*/
%let mean=0.195 ;
%let max=0.26 ;
%let min=0.13 ;
data have;
call streaminit(123);
cdf_min = cdf("Normal", &min., &mean., 0.03);
cdf_max = cdf("Normal", &max., &mean., 0.03);
do i=1 to 1000;
quantile=quantile("Normal", cdf_min + (cdf_max - cdf_min)*rand('uniform'), &mean., 0.03 );
output;
end;
run;
proc univariate data=have normal;
var quantile;
histogram quantile/normal;
run;
@Defense wrote:
Any one know how to simulate a dataset by given parameters below:
Given parameters: mean=0.195, max=0.26, min=0.13,
Request: random generate a 8 observation dataset with normal distribution.
I try to use rand, but it sounds no option for max and min
Do you have any guidance as to what distribution is required here? It can't be normal with a minimum and maximum.
You could cheat and use a normal distribution where the standard deviation is so large that you will virtually never get a value below the min or above the max.
@PaigeMiller is correct. A normal distribution can take values from negative infinity to positive infinity. You can get "close" to your maximum and minimum by choosing a standard deviation of the range divided by 6. If you do that, keep in mind that you may still get values above your maximum and/or below your minimum.
The normal distribution only has the mean and standard deviation as parameters. The best you could do would be to choose a standard deviation that will tend to keep the extremes within the min and max that you want. The following uses a sixth of the range as the standard deviation and generates 10,000 observations. Different. seed values in STREAMINIT, different sample sizes, and different proportions of the range will give different results. You'll want to experiment.
data rand;
call streaminit(3525);
mean=.195; std=(.26-.13)/6;
do i=1 to 10000;
random=rand("normal", mean, std );
output;
end;
run;
proc means mean min max std;
var random;
run;
Thanks for replying. Not sure why using "sixth of the range as the standard deviation".
In addition, I am trying the similar:
data symm(keep=y);
%let
data symm(keep=y);
%let st=0.0012;
seed = 11907665 ;
do i = 1 to 8;
y = rand("Normal", 0.19,&st );
if 0.26>=y>=0.13 then
output;
end;
run;
;
seed = 11907665 ;
do i = 1 to 8;
y = rand("Normal", 0.19,&st );
if 0.26>=y>=0.13 then
output;
end;
run;
I will try st=1/6(max-min), 1/4........1/8 until the output in 0.26>=y>=0.13 that range. Is that make sense
Thanks😁😀
Hello @Defense,
Glad to see that you've got great answers from the experts. Then it would be fair and help later readers if you marked the most helpful reply as the accepted solution, not your own "thank you" post. Could you please change that? It's very easy: Select a different post as the solution after clicking "Not the Solution" in the option menu (see icon below) of the current solution.
I like to do that. But there are only three icons "Add tag", "Quick reply" and "Reply". No"Not the Solution" icon. Pleae let me know how...Thank
@Defense wrote:
I like to do that. But there are only three icons "Add tag", "Quick reply" and "Reply". No"Not the Solution" icon. Pleae let me know how...Thank
Click the icon (three horizontal bars) shown in the screenshot in my previous post. This opens the option menu, which should contain the item "Not the Solution" among others.
You can calculated P value for MIN and MAX value(take them as percentile).
After that ,sample from PValue_MIN and PValue_MAX , mapping these P value back to percentile.
Check @Rick_SAS 's blog
https://blogs.sas.com/content/iml/2013/07/24/the-truncated-normal-in-sas.html
/*
You can calculated P value for MIN and MAX value(take them as percentile).
After that ,sample from PValue_MIN and PValue_MAX , mapping these P value back to percentile.
Check @Rick_SAS 's blog
https://blogs.sas.com/content/iml/2013/07/24/the-truncated-normal-in-sas.html
*/
%let mean=0.195 ;
%let max=0.26 ;
%let min=0.13 ;
data have;
call streaminit(123);
cdf_min = cdf("Normal", &min., &mean., 0.03);
cdf_max = cdf("Normal", &max., &mean., 0.03);
do i=1 to 1000;
quantile=quantile("Normal", cdf_min + (cdf_max - cdf_min)*rand('uniform'), &mean., 0.03 );
output;
end;
run;
proc univariate data=have normal;
var quantile;
histogram quantile/normal;
run;
This is a great solution. Is 0.03 come from (max-min)/4=S.D?
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.