What I want is to create a dataset which has three columns. The first column is digit(1-5). The second column is (A-C). The third column is a random number(0,1)
The sample:
1 A 0.1 1 B 0.2 1 C 0.5 2 A 0.8 2 B 0.3 2 C 0.5 3 A 0.2 3 B 0.2 3 C 0.3 ... 5 A 0.3 5 B 0.9 5 C 0.3
My code:
data DESIGN(drop=i j k); array result[3] $ Block Treatment RandomDigit; do i = 1 to 5; do j = 1 to 3; do k = 1 to 3; if(k=1) then result[i] = i; if(k=2) then result[i]=j; if(k=3) then result[i]=RAND("Uniform"); end; end; end; datalines; run;
Thanks for correct my errors.
You have many SAS programming concepts mixed up in your code. Understanding how the following code works should help you:
data design;
call streamInit(7768756); /* seed for random numbers */
do block = 1 to 5;
do treatment = "A", "B", "C";
randomDigit = round(rand("UNIFORM"), 0.1);
output;
end;
end;
run;
proc print; run;
You have many SAS programming concepts mixed up in your code. Understanding how the following code works should help you:
data design;
call streamInit(7768756); /* seed for random numbers */
do block = 1 to 5;
do treatment = "A", "B", "C";
randomDigit = round(rand("UNIFORM"), 0.1);
output;
end;
end;
run;
proc print; run;
The ability to use lists of values in Do loops and to use Character values as loop indices is one of the nice things about SAS. There were a few times when I was coding in FORTRAN I would cheerfully have taken a compiler designer out for drinks if they would include such things.
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.