Hi,
I have the following code sent to me by Reeza:
data random;
array s(60) s1-s60 (60*0);
array p(6) p1-p6;
do i=1 to 6;
do while(p(i)=.);
p(i)=floor(rand('uniform')*60+1);
if s(p(i))=0 then s(p(i))=1;
else p(i)=.;
end;
end;
keep p1-p6;
call sortn(of p(*));
run;
This code create six random numbers from 1 to 60 without duplicating them.
Now i need a loop to create 60 lines with diferente possibilities, the sequence (can't,may not) duplicate
What i mean: if the sequence is: 1,2,3,4,5,6 the next line may not duplicate, so it can be any other sequence,
1,2,3,4,5,7 or 13,24, 25,30,57,58
Thanks in advance,
Rodrigo
Here is the code:
data temp(keep=r x1-x6);
array x[60];
seed=3141592653;
do i=1 to 60;
x[i]=i;
end;
do n=1 to 100;
call rancomb(seed, 6, of x[*]);
r=ranuni(577215);
output;
end;
drop i n;
run;
proc sort data=temp nodupkey;
by x1-x6;
run;
proc sort data=temp;
by r;
run;
data want;
set temp(obs=60 drop=r);
run;
No, order doesn't metter but what metter is: if one sequence exists, it can not be duplicated.
That's all, thanks
I'm not sure that you understood Reeza's question the same way as I did: Would you regard the two sequences 1,2,3,4,5,6 and 1,2,3,4,6,5 as duplicates (because they contain the same numbers and "order doesn't matter")?
Oh yes, this can't happen.
Thanks
Hum, it's ok but what i need is sixty different possibilities of sequences.
Thanks
No problem: As Reeza wrote, you create 100 sequences and then remove (possible) duplicates and then select 60 of these. I am just writing a code example for you.
Here is the code:
data temp(keep=r x1-x6);
array x[60];
seed=3141592653;
do i=1 to 60;
x[i]=i;
end;
do n=1 to 100;
call rancomb(seed, 6, of x[*]);
r=ranuni(577215);
output;
end;
drop i n;
run;
proc sort data=temp nodupkey;
by x1-x6;
run;
proc sort data=temp;
by r;
run;
data want;
set temp(obs=60 drop=r);
run;
Thanks, Reeza. I was looking at Example 1 in the online help for CALL RANCOMB, where they initialize their array the inelegant way: array x x1-x5 (1 2 3 4 5);
Amazing man, that't exactly what i need, but if i would need 50.063.860 ()
just asking !
How much should i need to create to get the top 50.063.860 ?
Is that 50 million?
EDIT: That's 60 choose 6 - ie all possible combinations.
If you want that, there's other, faster ways to obtain it than this method.
Yes
The exactly number is 50.063.860
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.