<?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: Randomization algorithm in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Randomization-algorithm/m-p/227273#M40932</link>
    <description>&lt;P&gt;How are you 'randomizing'?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It almost sounds as if you might want to look into Proc Surveyselect and the amount spent might be considered a size measure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 25 Sep 2015 14:31:15 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2015-09-25T14:31:15Z</dc:date>
    <item>
      <title>Randomization algorithm</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomization-algorithm/m-p/227269#M40930</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a rolled up data set that contains a metric that counts the number of members and Dollars spent:&lt;/P&gt;&lt;P&gt;AgeGroup Region Members Spend&lt;/P&gt;&lt;P&gt;20-24 West 1 50&lt;/P&gt;&lt;P&gt;20-24 East 4 250&lt;/P&gt;&lt;P&gt;20-24 South 2 80&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;For any cell where Members LE 3 I randomize to 0 or 3 and adjust the spend accordingly:&lt;/P&gt;&lt;P&gt;AgeGroup Region Members Spend&lt;/P&gt;&lt;P&gt;20-24 West 0 0&lt;/P&gt;&lt;P&gt;20-24 East 4 250&lt;/P&gt;&lt;P&gt;20-24 South 3 120&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;At the end I evaluate the overall % difference to calclate the possible bias from new to old:&lt;/P&gt;&lt;P&gt;MemberBias = 7/7-1 = 0%&lt;/P&gt;&lt;P&gt;SpendBias = 370/380-1=-2.6%&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's where i'm stuck.&lt;/P&gt;&lt;P&gt;IF MemberBias OR SpendBias is GE +/- 1% re-run the randomization until both is under +-1% then keep that final dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure how to structure the logic in my code to do this, any help greatly appreciated.&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2015 13:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomization-algorithm/m-p/227269#M40930</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2015-09-25T13:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Randomization algorithm</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomization-algorithm/m-p/227273#M40932</link>
      <description>&lt;P&gt;How are you 'randomizing'?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It almost sounds as if you might want to look into Proc Surveyselect and the amount spent might be considered a size measure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2015 14:31:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomization-algorithm/m-p/227273#M40932</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-09-25T14:31:15Z</dc:date>
    </item>
    <item>
      <title>Re: Randomization algorithm</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomization-algorithm/m-p/227283#M40934</link>
      <description>&lt;P&gt;Sorry 'Randomizing' may not be the right title for this thread.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am randomizing using Rand("uniform")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Confidentialized ; Set Rollup(Rename=(Members=tmpMembers Spend=tmpSpend)) ;&lt;BR /&gt;If tmpMembers LE 3 then do ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;Random=rand("Uniform");&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Members=0 ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;IF Random GT 0.5 then Members=3 ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Dollars=(Members/tmpMembers)*tmpSpend;&lt;BR /&gt;end ;&lt;BR /&gt;&lt;BR /&gt;IF tmpMembers GT 3 then do ; Members =tmpMembers ; Spend=tmpSpend ; end ;&lt;BR /&gt;&amp;nbsp;run ;&lt;BR /&gt;&lt;BR /&gt;*** BIAS Check ;&lt;BR /&gt;Proc SQL ;&lt;BR /&gt;Create table BiasCheck as SElect&lt;BR /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;sum(Members)/sum(tmpMembers)-1 as MemberBias format Percent8.2,&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Sum(Spend)/Sum(tmpSpend)-1 as SpendBias format Percent8.2&lt;BR /&gt;From Confidentialized ;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc print data=biascheck ; run ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Essentially, based on the results of the Bias check, i'd like to re-iterate the confidentialization code so I can 'promote' the version where both bias is less than 1% difference.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2015 15:19:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomization-algorithm/m-p/227283#M40934</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2015-09-25T15:19:42Z</dc:date>
    </item>
    <item>
      <title>Re: Randomization algorithm</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomization-algorithm/m-p/227301#M40942</link>
      <description>&lt;P&gt;I suggest using a macro approach. If you create a macro with a %do %until loop you can repeat your data confidentialized &amp;amp; proc sql steps until your bias criteria is met. Something like the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro bias;&lt;/P&gt;&lt;P&gt;%let ok_bias=0;&lt;/P&gt;&lt;P&gt;%do %until (&amp;amp;ok_bias=1);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data confidentialized; set rollup(Rename=(Members=tmpMembers Spend=tmpSpend)) ;&lt;BR /&gt;If tmpMembers LE 3 then do ;&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*** BIAS Check ;&lt;BR /&gt;Proc SQL ;&lt;BR /&gt;Create table&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;set BiasCheck;&lt;/P&gt;&lt;P&gt;if memberbias lt .01 and spendbias lt .01 then call symput('ok_bias','1');&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%bias;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Sep 2015 16:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomization-algorithm/m-p/227301#M40942</guid>
      <dc:creator>michelle_delaurentis_sas_com</dc:creator>
      <dc:date>2015-09-25T16:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: Randomization algorithm</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomization-algorithm/m-p/227478#M40998</link>
      <description>&lt;P&gt;Thank you for your suggestion, it works great.&lt;/P&gt;&lt;P&gt;How would I alter the code to have a counter for&amp;nbsp;the number of iterations it took to finally be promoted?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2015 13:26:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomization-algorithm/m-p/227478#M40998</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2015-09-28T13:26:08Z</dc:date>
    </item>
    <item>
      <title>Re: Randomization algorithm</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomization-algorithm/m-p/227512#M41006</link>
      <description>&lt;P&gt;Before the %do intialize your counter and then increment within the loop&lt;/P&gt;
&lt;P&gt;%let counter=0;&lt;/P&gt;
&lt;P&gt;%do .....;&lt;/P&gt;
&lt;P&gt;%let counter = %eval(&amp;amp;counter + 1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;IF you want to see the value of counter outside the loop you will need to make it GLOBAL variable though.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2015 15:00:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomization-algorithm/m-p/227512#M41006</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-09-28T15:00:51Z</dc:date>
    </item>
    <item>
      <title>Re: Randomization algorithm</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomization-algorithm/m-p/228876#M41362</link>
      <description>Thank you ballardw. &lt;BR /&gt;&lt;BR /&gt;I'm trying to alter the code so the loop will break after 100 iterations OR bias is below the threshold and somehow print out which one was it that kicked it out. &lt;BR /&gt;&lt;BR /&gt;Thanks again for your help.</description>
      <pubDate>Wed, 07 Oct 2015 13:41:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomization-algorithm/m-p/228876#M41362</guid>
      <dc:creator>DangIT</dc:creator>
      <dc:date>2015-10-07T13:41:55Z</dc:date>
    </item>
    <item>
      <title>Re: Randomization algorithm</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Randomization-algorithm/m-p/228935#M41372</link>
      <description>&lt;P&gt;Give this a try.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro bias;&lt;/P&gt;
&lt;P&gt;%let counter=1;&lt;/P&gt;
&lt;P&gt;%let ok_bias=0;&lt;/P&gt;
&lt;P&gt;%do %until (&amp;amp;ok_bias=1 or counter gt 100);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data confidentialized; set rollup(Rename=(Members=tmpMembers Spend=tmpSpend)) ;&lt;BR /&gt;If tmpMembers LE 3 then do ;&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;*** BIAS Check ;&lt;BR /&gt;Proc SQL ;&lt;BR /&gt;Create table&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;set BiasCheck;&lt;/P&gt;
&lt;P&gt;if memberbias lt .01 and spendbias lt .01 then call symput('ok_bias','1');&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let counter=%eval(&amp;amp;counter + 1);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;ok_bias was the ok_bias value;&lt;/P&gt;
&lt;P&gt;%put &amp;amp;counter iterations occurred.;&lt;/P&gt;
&lt;P&gt;%mend;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%bias;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Oct 2015 17:05:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Randomization-algorithm/m-p/228935#M41372</guid>
      <dc:creator>michelle_delaurentis_sas_com</dc:creator>
      <dc:date>2015-10-07T17:05:08Z</dc:date>
    </item>
  </channel>
</rss>

