COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### How to generate non-repeated random integers

• Email
• Follow

```Dear all,
My problem is like this.
I want to simulate artificial data ranking 15 criteria (C1, .... ,
C15).
So, each observation should have any rank value between 1 and 15 to
each variable (criterion).
To do so, I have to assign an integer number between 1 and 15 to each
criterion without repetition of them.
After repeating this process, I wish to have 100 observations.

Best regards,
Kilkon

```
 0

See related articles to this posting

```Hi Kilkon

Hope the code below does what you're after:

data _null_;
length ValList \$ 30;
ValList=put(1,z2.);
do i=2 to 15;
ValList=cats(ValList,put(i,z2.));
end;
call symput('ValList',cats(ValList));
run;
%put ValList=&ValList;

data want(keep=ID C1-C15);
array c {15} 8.;
do ID=1 to 100;
ValList="&ValList";
do i=1 to 15;
RemainingElements=length(ValList)/2;
PickElement=ceil(ranuni(0)*RemainingElements);
c{i}=substr(ValList,(2*PickElement -1),2);

substr(ValList,(2*PickElement -1),2)='';
ValList=compress(ValList);
end;
output;
end;
run;

proc print data=want;
var ID C1-C15;
run;

HTH
Patrick
```
 0