<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: generate a random integer without duplicate in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/generate-a-random-integer-without-duplicate/m-p/765056#M242303</link>
    <description>&lt;PRE&gt;Data have  ;
infile datalines ;
input name $20. ;
datalines ;
Henry
Robert
Martin
Salah
Carla
Jamal
David
Jeff
Fred
Samuel
Nasser
Kylian
Lionel
Barbara
;
run ;

data id;
 set have;
 n+1;
 rand=rand('uniform');
 keep n rand;
run;
proc sort data=id;by rand;run;

data want;
 merge have id(drop=rand);
run;&lt;/PRE&gt;</description>
    <pubDate>Tue, 31 Aug 2021 13:41:54 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2021-08-31T13:41:54Z</dc:date>
    <item>
      <title>generate a random integer without duplicate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/generate-a-random-integer-without-duplicate/m-p/765050#M242300</link>
      <description>&lt;PRE&gt;Data have  ;
infile datalines ;
input name $20. ;
datalines ;
Henry
Robert
Martin
Salah
Carla
Jamal
David
Jeff
Fred
Samuel
Nasser
Kylian
Lionel
Barbara
run ;&lt;/PRE&gt;
&lt;P&gt;hello,&lt;/P&gt;
&lt;P&gt;I have a team with 14 persons. I would like to give a number to each person by random.&lt;/P&gt;
&lt;P&gt;I tried this: person_number = ceil(ranuni(1) * 14) ; but the number 8 appaers 3 times.&lt;/P&gt;
&lt;P&gt;how to do that without duplicates (each person should have a uniq number between 1 and 14)?&lt;/P&gt;
&lt;P&gt;thanks in adance&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 13:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/generate-a-random-integer-without-duplicate/m-p/765050#M242300</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2021-08-31T13:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: generate a random integer without duplicate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/generate-a-random-integer-without-duplicate/m-p/765056#M242303</link>
      <description>&lt;PRE&gt;Data have  ;
infile datalines ;
input name $20. ;
datalines ;
Henry
Robert
Martin
Salah
Carla
Jamal
David
Jeff
Fred
Samuel
Nasser
Kylian
Lionel
Barbara
;
run ;

data id;
 set have;
 n+1;
 rand=rand('uniform');
 keep n rand;
run;
proc sort data=id;by rand;run;

data want;
 merge have id(drop=rand);
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Aug 2021 13:41:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/generate-a-random-integer-without-duplicate/m-p/765056#M242303</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-08-31T13:41:54Z</dc:date>
    </item>
    <item>
      <title>Re: generate a random integer without duplicate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/generate-a-random-integer-without-duplicate/m-p/765057#M242304</link>
      <description>thanks Ksharp for your quick respons by I encounter ERROR: No BY statement was specified for a MERGE statement.&lt;BR /&gt;</description>
      <pubDate>Tue, 31 Aug 2021 13:47:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/generate-a-random-integer-without-duplicate/m-p/765057#M242304</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2021-08-31T13:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: generate a random integer without duplicate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/generate-a-random-integer-without-duplicate/m-p/765059#M242306</link>
      <description>&lt;P&gt;thanks ksharp for your quick respons but I encounter&lt;/P&gt;
&lt;P&gt;ERROR: No BY statement was specified for a MERGE statement.&lt;/P&gt;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 13:48:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/generate-a-random-integer-without-duplicate/m-p/765059#M242306</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2021-08-31T13:48:58Z</dc:date>
    </item>
    <item>
      <title>Re: generate a random integer without duplicate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/generate-a-random-integer-without-duplicate/m-p/765061#M242308</link>
      <description>&lt;P&gt;If you have SAS/IML licensed, it's very straightforward with the sample() function.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
 call randseed(27513);
 random_digit = t(sample(1:14, 14, "WOR"));

 create rand var {random_digit}; 
  append;      
 close rand; 
quit;

data want;
 merge have rand;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Aug 2021 13:56:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/generate-a-random-integer-without-duplicate/m-p/765061#M242308</guid>
      <dc:creator>ChanceTGardener</dc:creator>
      <dc:date>2021-08-31T13:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: generate a random integer without duplicate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/generate-a-random-integer-without-duplicate/m-p/765063#M242310</link>
      <description>&lt;P&gt;Thanks a lot !&lt;/P&gt;
&lt;P&gt;could you please explain &lt;SPAN class="token function keyword"&gt;randseed&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;27513&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; ?&lt;/P&gt;
&lt;P&gt;regards&lt;/P&gt;
&lt;P&gt;Nass&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 14:12:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/generate-a-random-integer-without-duplicate/m-p/765063#M242310</guid>
      <dc:creator>Nasser_DRMCP</dc:creator>
      <dc:date>2021-08-31T14:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: generate a random integer without duplicate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/generate-a-random-integer-without-duplicate/m-p/765067#M242312</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/147725"&gt;@Nasser_DRMCP&lt;/a&gt;&amp;nbsp;and later readers of this thread,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is another option using just one DATA step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
array _r[14] _temporary_ (1:14);
if _n_=1 then do;
  _iorc_=2718; /* random seed */
  call ranperm(_iorc_, of _r[*]);
end;
set have;
person_number=_r[_n_];
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 31 Aug 2021 14:25:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/generate-a-random-integer-without-duplicate/m-p/765067#M242312</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-08-31T14:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: generate a random integer without duplicate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/generate-a-random-integer-without-duplicate/m-p/765068#M242313</link>
      <description>&lt;P&gt;A seed is a number that initializes the random number generator. By keeping it fixed (to 27513 in this case), it ensures the sampling results stay the same each time the code is ran.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any seed &amp;gt;0 ensures repeatable results when the code is re-ran. I chose 27513 arbitrarily (it's the zip code for the SAS campus in Cary) so that we'd both get the same results.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the results to change every time the code is ran, set call randseed(0).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 14:29:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/generate-a-random-integer-without-duplicate/m-p/765068#M242313</guid>
      <dc:creator>ChanceTGardener</dc:creator>
      <dc:date>2021-08-31T14:29:04Z</dc:date>
    </item>
    <item>
      <title>Re: generate a random integer without duplicate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/generate-a-random-integer-without-duplicate/m-p/765315#M242405</link>
      <description>Add one more option:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;options mergenoby=nowarn;&lt;BR /&gt;data want;&lt;BR /&gt; merge have id(drop=rand);&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Wed, 01 Sep 2021 12:02:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/generate-a-random-integer-without-duplicate/m-p/765315#M242405</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-09-01T12:02:37Z</dc:date>
    </item>
  </channel>
</rss>

