So I am creating a scoring Macro for a questionnaire while I wait for my data to arrive.
I would like to create a dataset to test out the scoring macro that I have created.
Basically, the dataset would be ID (1,2,3,4) and Var1-var30, where Var1-30 have randomly generated whole number values between 1 and 6. Also I would like to have a seed to start so I can replicate the same dataset again. I need maybe 10 records at most.
I did some quick googling and can't seem to figure this out. The rand function I found seem to come up with numbers with decimal values (which is not what I want, I want whole numbers 1,2,3,4,5 or 6). I think this should be a basic task but I can't seem to figure it out 😞 So I am hoping someone can help me
Low seeds generate approximately random numbers, but that's probably all you will need for test data.
data want;
array var {30};
do obsno=1 to 10;
id = ceil(ranuni(12345) * 4);
do seed=1 to 30;
var{seed} = ceil(ranuni(seed) * 6);
end;
output;
end;
run;
See if this gives you a start.
data want;
array v var1-var30;
call streaminit (123); /* this makes the random results reproducable*/
do id=1 to 10;
do i=1 to dim(v);
/* the decimal values refer to the proportion of responses that should have
the order value. ('table', .4, .3, .2, .1) would have 40% with value 1,
30% with 2, 20% with 3 and 10% with 1.. The values should total to 1.
adjust as desired
The following line says each of the varaibles with have the same overall
distribution but the values per individual record will vary.
If you want to have different distributions than you could have
single line per var and skip the i loop for array, OR have multiple
arrays each group with a similar distribution
*/
v[i]= rand('table', .25, .15, .18, .12, .2, .1);
end;
output;
end;
drop i;
run;
Low seeds generate approximately random numbers, but that's probably all you will need for test data.
data want;
array var {30};
do obsno=1 to 10;
id = ceil(ranuni(12345) * 4);
do seed=1 to 30;
var{seed} = ceil(ranuni(seed) * 6);
end;
output;
end;
run;
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.