<?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: Distribute a variable according to another in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Distribute-a-variable-according-to-another/m-p/700873#M214546</link>
    <description>&lt;P&gt;Use the RAND('table', ...) function&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0fpeei0opypg8n1b06qe4r040lv.htm&amp;amp;locale=en#p0rssof65ddoyyn1s3kfdap849lr"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0fpeei0opypg8n1b06qe4r040lv.htm&amp;amp;locale=en#p0rssof65ddoyyn1s3kfdap849lr&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if x=1 then y=rand('table',0.01,0.1,0.4,0.49);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 23 Nov 2020 10:44:31 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-11-23T10:44:31Z</dc:date>
    <item>
      <title>Distribute a variable according to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distribute-a-variable-according-to-another/m-p/700871#M214544</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;BR /&gt;I would like to allocate a (categorical) variable ( Y=1,2,3,4) to each observation with a precise repartition, in function of another variable (X). I explain myself :&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;If X=0, I want :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;- 1% of the population with Y=1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;- 10%&amp;nbsp;of the population with Y=2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;- 40%&amp;nbsp;&amp;nbsp;&amp;nbsp;of the population with Y=3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;- 49%&amp;nbsp;of the population with Y=4&lt;BR /&gt;&lt;BR /&gt;And if X=1, I want :&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;- 2% of the population with Y=1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;- 12%&amp;nbsp;of the population with Y=2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;- 56%&amp;nbsp;&amp;nbsp;&amp;nbsp;of the population with Y=3&lt;/P&gt;
&lt;P&gt;&amp;nbsp;- 30%&amp;nbsp;of the population with Y=4&lt;BR /&gt;&lt;BR /&gt;Etc until X=10&lt;BR /&gt;&lt;BR /&gt;I know how to make the do loop and the conditional statement :&lt;BR /&gt;Do X=0 to 10 ;&lt;BR /&gt;If X=i then ...&lt;BR /&gt;i=i+1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I don't know how to allocate each observation to Y in the right proportions.&lt;BR /&gt;Of course, I know for each X what the repartition (in percentage) should be. I just need to know how to allocate the observations to each level of Y.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Thank you by advance for your help !&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 10:37:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distribute-a-variable-according-to-another/m-p/700871#M214544</guid>
      <dc:creator>Mathis1</dc:creator>
      <dc:date>2020-11-23T10:37:00Z</dc:date>
    </item>
    <item>
      <title>Re: Distribute a variable according to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distribute-a-variable-according-to-another/m-p/700872#M214545</link>
      <description>&lt;P&gt;How many different values can X have?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, can you provide some sample data and what your desired result looks like? Makes it much easier to provide usable code.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 10:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distribute-a-variable-according-to-another/m-p/700872#M214545</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-23T10:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: Distribute a variable according to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distribute-a-variable-according-to-another/m-p/700873#M214546</link>
      <description>&lt;P&gt;Use the RAND('table', ...) function&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0fpeei0opypg8n1b06qe4r040lv.htm&amp;amp;locale=en#p0rssof65ddoyyn1s3kfdap849lr"&gt;https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p0fpeei0opypg8n1b06qe4r040lv.htm&amp;amp;locale=en#p0rssof65ddoyyn1s3kfdap849lr&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if x=1 then y=rand('table',0.01,0.1,0.4,0.49);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Nov 2020 10:44:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distribute-a-variable-according-to-another/m-p/700873#M214546</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-23T10:44:31Z</dc:date>
    </item>
    <item>
      <title>Re: Distribute a variable according to another</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Distribute-a-variable-according-to-another/m-p/700939#M214578</link>
      <description>&lt;P&gt;Exactly how many observations are you going to process?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you only have 25 records where X=1 it is going to be very hard to get any distribution that "exactly matches" the stated percentages. (1 value of y=1 is 4% in this case). Other similar issues will exist with other numbers of records with any given X value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So what would expect for a "distribution" if you only have 25 X=1 records? or 50 X=0 (1% = half a record or Y=1 is 2%).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is unlikely to be able to match any "exact distribution" if the number of X= records is not exactly 100 or a multiple of 100. Also and "exact distribution" likely is not going to be a true random distribution if that is what is desired.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 15:50:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Distribute-a-variable-according-to-another/m-p/700939#M214578</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-11-23T15:50:58Z</dc:date>
    </item>
  </channel>
</rss>

