<?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: Recode with probabilities in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Recode-with-probabilities/m-p/106708#M22240</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you have the categories already in a dataset then you can use proc format with cntlin and then apply the format, you don't have to type out the boundaries. What does your original data look like from the macro?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 21 Dec 2012 22:42:26 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2012-12-21T22:42:26Z</dc:date>
    <item>
      <title>Recode with probabilities</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recode-with-probabilities/m-p/106704#M22236</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Suppose that probm1-probm10 are cumulative probabilities where probm10=1. The variable MUNIC should be recode following randomly assuming those probabilities. For this purpose, I write thoses lines:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;u=rand('uniform');&lt;/P&gt;&lt;P&gt;if u&amp;lt;probm1 then MUNIC=1;&lt;/P&gt;&lt;P&gt;if probm1&amp;lt;=u&amp;lt;probm2 then MUNIC=2;&lt;/P&gt;&lt;P&gt;if probm2&amp;lt;=u&amp;lt;probm3 then MUNIC=3;&lt;/P&gt;&lt;P&gt;if probm3&amp;lt;=u&amp;lt;probm4 then MUNIC=4;&lt;/P&gt;&lt;P&gt;if probm4&amp;lt;=u&amp;lt;probm5 then MUNIC=5;&lt;/P&gt;&lt;P&gt;if probm5&amp;lt;=u&amp;lt;probm6 then MUNIC=6;&lt;/P&gt;&lt;P&gt;if probm6&amp;lt;=u&amp;lt;probm7 then MUNIC=7;&lt;/P&gt;&lt;P&gt;if probm7&amp;lt;=u&amp;lt;probm8 then MUNIC=8;&lt;/P&gt;&lt;P&gt;if probm8&amp;lt;=u&amp;lt;probm9 then MUNIC=9;&lt;/P&gt;&lt;P&gt;if probm9&amp;lt;=u&amp;lt;probm10 then MUNIC=10;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My question: is there a more simple way to do it? With 10 categories, this isn't so huge, but I'll need to do the same with over 100 categories and thus, I don't think I did the best way.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Dec 2012 21:47:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recode-with-probabilities/m-p/106704#M22236</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2012-12-21T21:47:56Z</dc:date>
    </item>
    <item>
      <title>Re: Recode with probabilities</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recode-with-probabilities/m-p/106705#M22237</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Why not use a FORMAT?&lt;/P&gt;&lt;P&gt;If you had the cutoffs as macro variables you could create it this way.&lt;/P&gt;&lt;P&gt;proc format ;&lt;/P&gt;&lt;P&gt; value munic &lt;/P&gt;&lt;P&gt;&amp;nbsp; 0 - &amp;amp;prob1 = 1&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;amp;prob1 - &amp;amp;prob2 = 2&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;amp;prob9 - &amp;amp;prob10 = 10&lt;/P&gt;&lt;P&gt; other = .&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;Then your code becomes &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; munic = input(put(u,munic.),best.);&lt;/P&gt;&lt;P&gt;You can also build the format from a dataset using the CNTLIN option of PROC FORMAT.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Dec 2012 21:54:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recode-with-probabilities/m-p/106705#M22237</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2012-12-21T21:54:42Z</dc:date>
    </item>
    <item>
      <title>Re: Recode with probabilities</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recode-with-probabilities/m-p/106706#M22238</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't think it's possible in my case, because variables probm1-probm10 are created following a big set of macros.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, the problem is the same if I have 100 categories. I try to find a way to write this in just some lines and not a hundred. I know it's possible in C++.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Dec 2012 21:59:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recode-with-probabilities/m-p/106706#M22238</guid>
      <dc:creator>Demographer</dc:creator>
      <dc:date>2012-12-21T21:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: Recode with probabilities</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recode-with-probabilities/m-p/106707#M22239</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If your solution in C++ involved arrays then thats one way in SAS. Some of the code below is incase your upper variable count changes so if you only had probm73 for example it will stop there.&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;array p {*} probm1 - probm100; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;do _i_ = 1 to (dim(p)-1); &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if _i_ = 1 and u &amp;lt; p[_i_] then Munic=_i_; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;else if p[_i_] &amp;lt;= u &amp;lt; p[_i_ + 1] then Munic=_i_; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;end; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Dec 2012 22:06:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recode-with-probabilities/m-p/106707#M22239</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2012-12-21T22:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: Recode with probabilities</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recode-with-probabilities/m-p/106708#M22240</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you have the categories already in a dataset then you can use proc format with cntlin and then apply the format, you don't have to type out the boundaries. What does your original data look like from the macro?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 21 Dec 2012 22:42:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recode-with-probabilities/m-p/106708#M22240</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2012-12-21T22:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: Recode with probabilities</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Recode-with-probabilities/m-p/106709#M22241</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Give this a try:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;seed = 123;&lt;/P&gt;&lt;P&gt;call rantbl(seed, .05, .2, .6, .1, result);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You should get 5% 1's, 20% 2's, 60% 3's, 10% 4's, and the residue (5)% 5's in result.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tom &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 22 Dec 2012 17:53:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Recode-with-probabilities/m-p/106709#M22241</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2012-12-22T17:53:37Z</dc:date>
    </item>
  </channel>
</rss>

