<?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: creating equal size bins in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/creating-equal-size-bins/m-p/627897#M77502</link>
    <description>&lt;P&gt;Thank you for the reply.&lt;/P&gt;&lt;P&gt;Not the same FREQ but approximately the same number of "exposures" (the variable in the dataset) in all 25 bin.&lt;/P&gt;&lt;P&gt;I tried PROC RANK but it doesn't seem to do the trick.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Feb 2020 13:43:01 GMT</pubDate>
    <dc:creator>pmotlagh</dc:creator>
    <dc:date>2020-02-27T13:43:01Z</dc:date>
    <item>
      <title>creating equal size bins</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-equal-size-bins/m-p/627647#M77498</link>
      <description>&lt;P&gt;I'm using SAS 9.4.&amp;nbsp; I have a dataset with the following variables: IDnum, exposures, cost.&lt;/P&gt;&lt;P&gt;I want to divide my dataset into 25 bins of equal exposures and then calculate the average cost of each of the 25 bins. I tried the following:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt; &lt;STRONG&gt;hpbin&lt;/STRONG&gt; data=TESTDATA output=out numbin=&lt;STRONG&gt;25&lt;/STRONG&gt; PSEUDO_QUANTILE;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; input exposures ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ID IDnum;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt; &lt;STRONG&gt;SORT&lt;/STRONG&gt; DATA=TESTDATA;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BY IDnum;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt; &lt;STRONG&gt;SORT&lt;/STRONG&gt; DATA=OUT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BY IDnum;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;DATA&lt;/STRONG&gt; ALL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MERGE TESTDATA OUT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BY IDnum;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt; &lt;STRONG&gt;MEANS&lt;/STRONG&gt; DATA=ALL;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; BY BIN_EXPOSURES;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; VAR cost;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; WEIGHT exposures;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; OUTPUT OUT=TWO MEAN=AVG_cost;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;RUN&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC HPBIN does not give the equal size exposure bins.&lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;</description>
      <pubDate>Wed, 26 Feb 2020 20:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-equal-size-bins/m-p/627647#M77498</guid>
      <dc:creator>pmotlagh</dc:creator>
      <dc:date>2020-02-26T20:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: creating equal size bins</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-equal-size-bins/m-p/627742#M77499</link>
      <description>&lt;P&gt;Do you mean equal FREQ bin ?&lt;/P&gt;
&lt;P&gt;If 'exposures' has tie value, it would not give you equal size bin, but almost equal .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also could try PROC RANKS :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc ranks data=have ties=high group=10 out=want ;&lt;/P&gt;
&lt;P&gt;var exposures;&lt;/P&gt;
&lt;P&gt;ranks rank_exposures;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 03:39:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-equal-size-bins/m-p/627742#M77499</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-02-27T03:39:38Z</dc:date>
    </item>
    <item>
      <title>Re: creating equal size bins</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-equal-size-bins/m-p/627897#M77502</link>
      <description>&lt;P&gt;Thank you for the reply.&lt;/P&gt;&lt;P&gt;Not the same FREQ but approximately the same number of "exposures" (the variable in the dataset) in all 25 bin.&lt;/P&gt;&lt;P&gt;I tried PROC RANK but it doesn't seem to do the trick.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 13:43:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-equal-size-bins/m-p/627897#M77502</guid>
      <dc:creator>pmotlagh</dc:creator>
      <dc:date>2020-02-27T13:43:01Z</dc:date>
    </item>
    <item>
      <title>Re: creating equal size bins</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-equal-size-bins/m-p/627900#M77503</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/114586"&gt;@pmotlagh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried PROC RANK but it doesn't seem to do the trick.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Could you explain further?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 13:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-equal-size-bins/m-p/627900#M77503</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-02-27T13:50:21Z</dc:date>
    </item>
    <item>
      <title>Re: creating equal size bins</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-equal-size-bins/m-p/627902#M77504</link>
      <description>&lt;P&gt;PROC RANK did not give me the equal "exposures" bins.&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 13:52:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-equal-size-bins/m-p/627902#M77504</guid>
      <dc:creator>pmotlagh</dc:creator>
      <dc:date>2020-02-27T13:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: creating equal size bins</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-equal-size-bins/m-p/627906#M77505</link>
      <description>&lt;P&gt;Your PROC MEANS code is using&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;BY BIN_EXPOSURES;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;but the data are not sorted by that variable. Perhaps you meant to use CLASS BIN_EXPOSURES.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Anyway, as KSharp said, you will get approximately equat bins, but tied observations might make some bins contain more than others. The Mapping table from PROC HPBIN tells you how many observations are in each bin. Run the following example and notice that all of the bins have approximately 40 observations, but some have a few more or less:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data testdata;
call streaminit(1);
do idnum = 1 to 1000;
  exposures = round(rand("Normal"), 0.01);
  cost = rand("Lognormal");
  output;
end;
run;

proc hpbin data=testdatA output=out numbin=25 PSEUDO_QUANTILE;
   input exposures;
   ID idnum;
   ods select Mapping;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;SPAN&gt;For more information about various binning methods and techniques in SAS, see &lt;A href="https://blogs.sas.com/content/iml/2019/08/07/essential-guide-binning-sas.html" target="_self"&gt;"The essential guide to binning in SAS,"&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;which includes a discussion of PROC HPBIN.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 13:59:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-equal-size-bins/m-p/627906#M77505</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-02-27T13:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: creating equal size bins</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-equal-size-bins/m-p/627951#M77511</link>
      <description>&lt;P&gt;Thanks Rick.&lt;/P&gt;&lt;P&gt;I think the problem then must be the many tied "exposures" in the data.&amp;nbsp; Is there an option that can be used to get around it?&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 15:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-equal-size-bins/m-p/627951#M77511</guid>
      <dc:creator>pmotlagh</dc:creator>
      <dc:date>2020-02-27T15:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: creating equal size bins</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-equal-size-bins/m-p/627963#M77513</link>
      <description>&lt;P&gt;In the article &lt;A href="https://blogs.sas.com/content/iml/2019/08/07/essential-guide-binning-sas.html" target="_self"&gt;"The essential guide to binning in SAS,":&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;- Scroll down the section "Quantile binning in SAS."&lt;/P&gt;
&lt;P&gt;- Read the fourth bullet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the article, I say"&lt;SPAN&gt;I do not endorse that practice" because it does not make sense to place observations are in the different bins when they have exactly the same values.&amp;nbsp;&lt;EM&gt;Caveat emptor!&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Feb 2020 16:11:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-equal-size-bins/m-p/627963#M77513</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2020-02-27T16:11:40Z</dc:date>
    </item>
    <item>
      <title>Re: creating equal size bins</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/creating-equal-size-bins/m-p/628896#M77602</link>
      <description>Thank you.</description>
      <pubDate>Mon, 02 Mar 2020 19:54:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/creating-equal-size-bins/m-p/628896#M77602</guid>
      <dc:creator>pmotlagh</dc:creator>
      <dc:date>2020-03-02T19:54:00Z</dc:date>
    </item>
  </channel>
</rss>

