How to generate non-repeated random integers

  • 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.

Your help will be appreciated.

Best regards,
Kilkon

0
Reply Netguy 7/6/2010 3:25:25 PM

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
Reply Patrick 7/7/2010 1:34:12 AM


1 Replies
855 Views

(page loaded in 0.055 seconds)

Similiar Articles:













7/25/2012 1:57:39 AM


Reply: