<?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: round number by probability in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/round-number-by-probability/m-p/619269#M181774</link>
    <description>&lt;P&gt;A simple solution&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   do x=1 to 10;
      output;
   end;
run;

data want;
   set have;
   r = mod (x, 3);
   if      r = 0 then rx = x;
   else if r = 1 then rx = ifn (rand('uniform') &amp;lt; 1/3, x+2, x-1);
   else if r = 2 then rx = ifn (rand('uniform') &amp;lt; 1/3, x-2, x+1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 22 Jan 2020 18:47:18 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2020-01-22T18:47:18Z</dc:date>
    <item>
      <title>round number by probability</title>
      <link>https://communities.sas.com/t5/SAS-Programming/round-number-by-probability/m-p/619258#M181769</link>
      <description>&lt;P&gt;I would like to round numbers (e.g. count of something) by probability:&lt;/P&gt;&lt;P&gt;If the count is a multiple of 3 with a remainder 0, it stays the same&lt;/P&gt;&lt;P&gt;If the count is a multiple of 3 with a remainder 1, it has 1/3 probability to round up, and 2/3 probability to round down.&lt;/P&gt;&lt;P&gt;If the count is a multiple of 3 with a remainder 2, it has 2/3 probability to round up, and 1/3 probability to round down.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I only know using floor and ceil to round up and down, but don't know how to use the probability.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2020 18:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/round-number-by-probability/m-p/619258#M181769</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2020-01-22T18:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: round number by probability</title>
      <link>https://communities.sas.com/t5/SAS-Programming/round-number-by-probability/m-p/619261#M181771</link>
      <description>&lt;P&gt;What do you want to round to? Your numbers are integers, correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a template to get you started..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   r = mod (x, 3);
   if      r = 0 then rx = x;
   else if r = 1 then ..;
   else if r = 2 then ..;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Jan 2020 18:32:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/round-number-by-probability/m-p/619261#M181771</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-01-22T18:32:59Z</dc:date>
    </item>
    <item>
      <title>Re: round number by probability</title>
      <link>https://communities.sas.com/t5/SAS-Programming/round-number-by-probability/m-p/619266#M181773</link>
      <description>&lt;P&gt;Sorry, my question is not clear.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to round integer numbers to base of 3. e.g. 4 will be rounded to 6 with prob=1/3, and to 3 with prob=2/3 i.e. if the number (integer)&amp;nbsp;is a multiple of 3 with a remainder 1, it has 1/3 probability to round up to a number base of 3, and 2/3 probability to round down to a number base of 3.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2020 18:36:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/round-number-by-probability/m-p/619266#M181773</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2020-01-22T18:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: round number by probability</title>
      <link>https://communities.sas.com/t5/SAS-Programming/round-number-by-probability/m-p/619269#M181774</link>
      <description>&lt;P&gt;A simple solution&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   do x=1 to 10;
      output;
   end;
run;

data want;
   set have;
   r = mod (x, 3);
   if      r = 0 then rx = x;
   else if r = 1 then rx = ifn (rand('uniform') &amp;lt; 1/3, x+2, x-1);
   else if r = 2 then rx = ifn (rand('uniform') &amp;lt; 1/3, x-2, x+1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Jan 2020 18:47:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/round-number-by-probability/m-p/619269#M181774</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-01-22T18:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: round number by probability</title>
      <link>https://communities.sas.com/t5/SAS-Programming/round-number-by-probability/m-p/619270#M181775</link>
      <description>Please show what your input data looks like and what you expect for output. Thanks!</description>
      <pubDate>Wed, 22 Jan 2020 18:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/round-number-by-probability/m-p/619270#M181775</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-01-22T18:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: round number by probability</title>
      <link>https://communities.sas.com/t5/SAS-Programming/round-number-by-probability/m-p/619278#M181777</link>
      <description>&lt;P&gt;Thanks for your reply. Couple of questions:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is rand('uniform')&amp;lt;1/3 the same as generating a prob-1/3 ? i know the uniform distribution, but is this a general use of it?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How about a more general solution for different base, e.g what if i want to round to a number of base 5, 10, 100, ....&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2020 19:17:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/round-number-by-probability/m-p/619278#M181777</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2020-01-22T19:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: round number by probability</title>
      <link>https://communities.sas.com/t5/SAS-Programming/round-number-by-probability/m-p/619280#M181778</link>
      <description>&lt;P&gt;It is just alike the data from draycut's reply. i have just one column of number and want to round it by adding the rounded number beside it. The key is how to round it by probability.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; do x=&lt;STRONG&gt;1&lt;/STRONG&gt; to &lt;STRONG&gt;10&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2020 19:20:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/round-number-by-probability/m-p/619280#M181778</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2020-01-22T19:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: round number by probability</title>
      <link>https://communities.sas.com/t5/SAS-Programming/round-number-by-probability/m-p/619306#M181785</link>
      <description>&lt;P&gt;For something more general, you could use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   do x=1 to 100;
      output;
   end;
run;

%let base=5;

data want;
set have;
alpha = 1 - mod(x, &amp;amp;base) / &amp;amp;base;
value = &amp;amp;base * int(x / &amp;amp;base);
rx = choosen( rand("table", alpha), value, &amp;amp;base + value);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Jan 2020 20:24:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/round-number-by-probability/m-p/619306#M181785</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2020-01-22T20:24:13Z</dc:date>
    </item>
    <item>
      <title>Re: round number by probability</title>
      <link>https://communities.sas.com/t5/SAS-Programming/round-number-by-probability/m-p/619345#M181812</link>
      <description>&lt;P&gt;Thanks, Would like to mark this as solution as well, bu the system won't let me.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jan 2020 22:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/round-number-by-probability/m-p/619345#M181812</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2020-01-22T22:13:36Z</dc:date>
    </item>
  </channel>
</rss>

