<?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: Assigning Random numbers to a given set of IDs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assigning-Random-numbers-to-a-given-set-of-IDs/m-p/296041#M61946</link>
    <description>&lt;PRE&gt;
Last code is not right. Try this one:



data have;
 do obs=1 to 2000;
  output;
 end;
run;
data temp;
 set have;
 ran=ranuni(0);
run;
proc rank data=temp out=want;
 var ran;
 ranks r;
run;
data want;
 set want;
 random=100000+r;
 drop r;
run;

proc sql;
select count(distinct random),max(random),min(random) from want;quit;


&lt;/PRE&gt;</description>
    <pubDate>Fri, 02 Sep 2016 04:12:31 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2016-09-02T04:12:31Z</dc:date>
    <item>
      <title>Assigning Random numbers to a given set of IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-Random-numbers-to-a-given-set-of-IDs/m-p/294411#M61426</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to assign random numbers to a given set of IDs. The reason for assinging random numbers to the IDs is to de-identify the information from the IDs. There should not be any relationship between the IDs and the Random numbers generated from them. For example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if I have a set of IDs as:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;IDs&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;Random Numbers&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;5768&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;5768&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2749&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2749&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2749&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;9574&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;9574&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;9574&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The random numbers in the above tables are just the examples. These numbers can be any given number until and unless there is no relationship between the IDs and Random numbers. The only intention for decoding the IDs is to secure the information. Again, these random numbers cannot be used to lookback the IDs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Aug 2016 14:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-Random-numbers-to-a-given-set-of-IDs/m-p/294411#M61426</guid>
      <dc:creator>danwarags</dc:creator>
      <dc:date>2016-08-26T14:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning Random numbers to a given set of IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-Random-numbers-to-a-given-set-of-IDs/m-p/294436#M61432</link>
      <description>&lt;PRE&gt;

data have;
input id;
cards;
1
1
2
2
2
3
4
5
5
;
run;
data want;
 set have;
 by id;
 retain ran;
 if first.id then ran=ceil(1000000000000*ranuni(0));
run;
&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Aug 2016 15:47:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-Random-numbers-to-a-given-set-of-IDs/m-p/294436#M61432</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-26T15:47:06Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning Random numbers to a given set of IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-Random-numbers-to-a-given-set-of-IDs/m-p/295845#M61867</link>
      <description>&lt;P&gt;Thanks Ksharp. This code works. If I wanted to assign random numbers in particular range how should I modify the code. For example for a given set of 2000 IDs I want to assign random numbers in the range 100000- 102000. How should I do this. For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Obs&lt;/TD&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1456&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3765&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;35632&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;89564&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/TD&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/TD&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/TD&gt;&lt;TD&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;580058&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My output should look something like:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Obs&lt;/TD&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Random&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1456&lt;/TD&gt;&lt;TD&gt;100000&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3765&lt;/TD&gt;&lt;TD&gt;101997&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;35632&lt;/TD&gt;&lt;TD&gt;101456&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;89564&lt;/TD&gt;&lt;TD&gt;100002&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2000&lt;/TD&gt;&lt;TD&gt;580058&lt;/TD&gt;&lt;TD&gt;102000&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the above example, the number of observations in the dataset are 2000. The Random numbers are assigned such that they are in particular range i.e 100000-102000.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help&lt;/P&gt;</description>
      <pubDate>Thu, 01 Sep 2016 14:18:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-Random-numbers-to-a-given-set-of-IDs/m-p/295845#M61867</guid>
      <dc:creator>danwarags</dc:creator>
      <dc:date>2016-09-01T14:18:35Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning Random numbers to a given set of IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-Random-numbers-to-a-given-set-of-IDs/m-p/296040#M61945</link>
      <description>&lt;PRE&gt;


data have;
 do obs=1 to 2000;
  output;
 end;
run;
data temp;
 set have;
 ran=ranuni(0);
run;
proc rank data=temp out=want;
 var ran;
 ranks r;
run;
data want;
 set want;
 random=100001+r;
 drop r;
run;



&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Sep 2016 04:09:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-Random-numbers-to-a-given-set-of-IDs/m-p/296040#M61945</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-09-02T04:09:56Z</dc:date>
    </item>
    <item>
      <title>Re: Assigning Random numbers to a given set of IDs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assigning-Random-numbers-to-a-given-set-of-IDs/m-p/296041#M61946</link>
      <description>&lt;PRE&gt;
Last code is not right. Try this one:



data have;
 do obs=1 to 2000;
  output;
 end;
run;
data temp;
 set have;
 ran=ranuni(0);
run;
proc rank data=temp out=want;
 var ran;
 ranks r;
run;
data want;
 set want;
 random=100000+r;
 drop r;
run;

proc sql;
select count(distinct random),max(random),min(random) from want;quit;


&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Sep 2016 04:12:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assigning-Random-numbers-to-a-given-set-of-IDs/m-p/296041#M61946</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-09-02T04:12:31Z</dc:date>
    </item>
  </channel>
</rss>

