Hi All,
I am trying to understand the RANUNI function. Trying to create a dataset using RANUNI
For Ex. I have a Dataset ACCOUNTS having the below-mentioned variables
ACCT_NUM, AFLAG RF1, RF2, RF3, RF4 rf2cnts
0000000001 0 0 1 1 1 1
0000000004 0 1 1 1 1 1
0000000005 0 0 0 0 1 0
000000300 0 0 0 0 0 0
I am using the below code to get a size and assign 1 rf2,rf3, and rf4 respectively if the value is 1 in a new variable (for eg. rfn)
data rf2 (drop = x n);
set accounts;
n = ranuni(5);
retain x 1;
if rfcnts eq 1 and x = 10 then do; * x = 10 number of rf2 needed with 1;
rf2f = 1;
x+1;
end;
else do;
rf2f = 0;
end;
run;
I am trying to understand when I run the same data step on the same dataset will the value of N change, have tried running the data step on the same dataset a couple of times but every 10-15 mins I still see the value of N is same. is this how it should be or change every time I run the data step with RANUNI in it and on the same dataset with the same values and size?
Kindly note I don't want to use SurveySelect, please see the output attached where we have unchanged values of N.
Kindly suggest.
Regards,
S
Hi @Santt0sh,
If you want n to change in virtually every run of the program, you can use the seed 0, i.e., n = ranuni(0). Then "the time of day is used to initialize the seed stream" (documentation), hence the automatic change. From the resulting random numbers (if you do not drop n from dataset RF2) you can even determine a non-zero seed that can be used to reproduce the same results, if needed.
(See also: Six reasons you should stop using the RANUNI function to generate random numbers.)
If you run the data step using the same SEED you should get the set series of random numbers.
If that is not what you want then use a different SEED value for each run.
Hi @Santt0sh,
If you want n to change in virtually every run of the program, you can use the seed 0, i.e., n = ranuni(0). Then "the time of day is used to initialize the seed stream" (documentation), hence the automatic change. From the resulting random numbers (if you do not drop n from dataset RF2) you can even determine a non-zero seed that can be used to reproduce the same results, if needed.
(See also: Six reasons you should stop using the RANUNI function to generate random numbers.)
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.