<?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 Bin variable into N equal length intervals in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Bin-variable-into-N-equal-length-intervals/m-p/568329#M159958</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with variable X which values theoretically range between 0 and 1. In practice, not every value or the min and max may be observed in the dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create N groups of equal interval length and assign each observation into one of those groups into variable Y. Some of these groups may be empty if there are no observations within the fixed interval.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example if N=100 then the first group would look like:&lt;/P&gt;&lt;P&gt;0-0.01&lt;/P&gt;&lt;P&gt;0.01-0.02&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;0.99-1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc rank seems to work only with percentiles or with the values observed in the data. Another option would be Proc format - however it would be very inefficient to write the boundaries of each of the N groups specifically.&lt;/P&gt;</description>
    <pubDate>Mon, 24 Jun 2019 10:00:08 GMT</pubDate>
    <dc:creator>KonstantinVasil</dc:creator>
    <dc:date>2019-06-24T10:00:08Z</dc:date>
    <item>
      <title>Bin variable into N equal length intervals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bin-variable-into-N-equal-length-intervals/m-p/568329#M159958</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset with variable X which values theoretically range between 0 and 1. In practice, not every value or the min and max may be observed in the dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create N groups of equal interval length and assign each observation into one of those groups into variable Y. Some of these groups may be empty if there are no observations within the fixed interval.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example if N=100 then the first group would look like:&lt;/P&gt;&lt;P&gt;0-0.01&lt;/P&gt;&lt;P&gt;0.01-0.02&lt;/P&gt;&lt;P&gt;...&lt;/P&gt;&lt;P&gt;0.99-1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc rank seems to work only with percentiles or with the values observed in the data. Another option would be Proc format - however it would be very inefficient to write the boundaries of each of the N groups specifically.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jun 2019 10:00:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bin-variable-into-N-equal-length-intervals/m-p/568329#M159958</guid>
      <dc:creator>KonstantinVasil</dc:creator>
      <dc:date>2019-06-24T10:00:08Z</dc:date>
    </item>
    <item>
      <title>Re: Bin variable into N equal length intervals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bin-variable-into-N-equal-length-intervals/m-p/568340#M159965</link>
      <description>Will PROC HPBIN suit your need? &lt;A href="http://support.sas.com/documentation/cdl/en/prochp/67530/HTML/default/viewer.htm#prochp_hpbin_overview01.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/prochp/67530/HTML/default/viewer.htm#prochp_hpbin_overview01.htm&lt;/A&gt;</description>
      <pubDate>Mon, 24 Jun 2019 11:48:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bin-variable-into-N-equal-length-intervals/m-p/568340#M159965</guid>
      <dc:creator>koyelghosh</dc:creator>
      <dc:date>2019-06-24T11:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Bin variable into N equal length intervals</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Bin-variable-into-N-equal-length-intervals/m-p/568341#M159966</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/189120"&gt;@KonstantinVasil&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you mean that Y should contain the group number (e.g. 1, 2, ..., 100 if N=100)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then simply use something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let N=100;

data want;
set have;
if x&amp;gt;.z then y=ceil(&amp;amp;N*x);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This would assign all values x in (0, 0.01] to y=1, all values x in (0.01, 0.02] to y=2, ... (0.99, 1] to y=100. Only the special case x=0 would be assigned to y=0. But if you want to assign 0 to the first interval (y=1), you can change the formula to&amp;nbsp;&lt;FONT face="courier new,courier"&gt;y=&lt;STRONG&gt;(x=0)+&lt;/STRONG&gt;ceil(&amp;amp;N*x)&lt;/FONT&gt;.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jun 2019 11:50:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Bin-variable-into-N-equal-length-intervals/m-p/568341#M159966</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-06-24T11:50:21Z</dc:date>
    </item>
  </channel>
</rss>

