I have the following simulation code to produce 1000 sets of data similar to "work.final" where the independent variables do not change in all the 1000 sets.
But I would like to add another condition. For each of the 1000 datasets, the frequency of the value 10, which is a simulated value of y should be 20%, the same way...the frequency of value 15 should be 10%.
%let NumSamples = 1000;
data s_new;
call streaminit(6578);
set work.final;
do SampleID=1 to &NumSamples;
mu = exp(1.5360 + 0.0140*x1 - 0.1016*x2 + 0.6216*x3);
k = 1/0.5345;
p = 1/(1+0.5345*mu);
y = rand('negbinomial', p, k);
output;
end;
run;
Do you want those frequencies to be exactly 20 and 10% or will something like this following do?
%let NumSamples = 1000;
data s_new;
call streaminit(6578);
do SampleID=1 to &NumSamples;
mu = exp(1.5360 + 0.0140*x1 - 0.1016*x2 + 0.6216*x3);
k = 1/0.5345;
p = 1/(1+0.5345*mu);
y = rand('negbinomial', p, k);
a=rand('Uniform');
if a<0.2 then y=10;
else if 0.2<=a<=0.3 then y=15;
end;
run;
Do you want those frequencies to be exactly 20 and 10% or will something like this following do?
%let NumSamples = 1000;
data s_new;
call streaminit(6578);
do SampleID=1 to &NumSamples;
mu = exp(1.5360 + 0.0140*x1 - 0.1016*x2 + 0.6216*x3);
k = 1/0.5345;
p = 1/(1+0.5345*mu);
y = rand('negbinomial', p, k);
a=rand('Uniform');
if a<0.2 then y=10;
else if 0.2<=a<=0.3 then y=15;
end;
run;
This would not work with the model I'm using on the simulated data. I previously tried rounding off some values of y (as shown below) to achieve the percentage...but I noticed that it was proving very difficult to get the exact percentage. I would really appreciate any incite that would get me the exact frequency of 10 and 15 to 20% and 10% respectively.
if (5 <= y <= 12) & rand("Bernoulli", 0.2) then
y10 = round(y, 10);
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!
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.
Ready to level-up your skills? Choose your own adventure.