<?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: How to find frequency of i in each bin of data? in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-find-frequency-of-i-in-each-bin-of-data/m-p/357840#M3472</link>
    <description>&lt;P&gt;So you only want to count the data for which label=1? &amp;nbsp;If so, use a WHERE clause to subset the data when you read it in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
use work.prtf_data where(label=1);
read all var {Score} into x;
close work.prtf_data;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I can't tell from your example if the LABEL variable is numeric or character. If it is character, then use&lt;/P&gt;
&lt;P&gt;WHERE(label='1')&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the general question "how do I count the number of observations in uneven bins," see &lt;A href="http://blogs.sas.com/content/iml/2013/07/15/cut-pts-and-uneven-bins.html" target="_self"&gt;"Bin observations by using custom cut points and unevenly spaced bins."&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 11 May 2017 13:26:53 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2017-05-11T13:26:53Z</dc:date>
    <item>
      <title>How to find frequency of i in each bin of data?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-find-frequency-of-i-in-each-bin-of-data/m-p/357827#M3471</link>
      <description>&lt;P&gt;Hi i have data with two variables one is score and other is binary variable "label".&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;score &amp;nbsp; &amp;nbsp;label&lt;/P&gt;&lt;P&gt;245 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;261 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;250 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;300 &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;270 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am interested to find counts of 1 in label variable for the given manual&amp;nbsp;bins. I have written code but it is giving only frequency of squares in the bins as.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
use work.prtf_data;
read all var {Score} into x;
close work.prtf_data;
 

cutpts = {.M 261 273 283 291 298 305 312 330 341 342 .I};
r = bin(x, cutpts);
 
call tabulate(BinNumber, Freq, r);
lbls = {"&amp;lt; 261" "262-273" "274-283" "284-291" "292-298" "299-305" "306-312" "313-330" "331-341" "&amp;gt; 342"};
print Freq[colname=lbls];&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;i want my results as&amp;nbsp;&lt;/P&gt;&lt;P&gt;"score" &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;"" 1 freq"&lt;/P&gt;&lt;P&gt;&amp;lt;261 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2&lt;/P&gt;&lt;P&gt;262-273 &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;.....&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please suggest me any solution. Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 11:21:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-find-frequency-of-i-in-each-bin-of-data/m-p/357827#M3471</guid>
      <dc:creator>ervinodsingh</dc:creator>
      <dc:date>2017-05-11T11:21:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to find frequency of i in each bin of data?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-find-frequency-of-i-in-each-bin-of-data/m-p/357840#M3472</link>
      <description>&lt;P&gt;So you only want to count the data for which label=1? &amp;nbsp;If so, use a WHERE clause to subset the data when you read it in:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc iml;
use work.prtf_data where(label=1);
read all var {Score} into x;
close work.prtf_data;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I can't tell from your example if the LABEL variable is numeric or character. If it is character, then use&lt;/P&gt;
&lt;P&gt;WHERE(label='1')&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the general question "how do I count the number of observations in uneven bins," see &lt;A href="http://blogs.sas.com/content/iml/2013/07/15/cut-pts-and-uneven-bins.html" target="_self"&gt;"Bin observations by using custom cut points and unevenly spaced bins."&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2017 13:26:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-find-frequency-of-i-in-each-bin-of-data/m-p/357840#M3472</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-05-11T13:26:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to find frequency of i in each bin of data?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-find-frequency-of-i-in-each-bin-of-data/m-p/357877#M3473</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
input score    label;
cards;
245       1
261       0
250       1
300       1
270       0
200       0
;
run;
proc iml;
use class;
read all var {score label} ;
close ;
 

cutpts = {.M 262 .I};
r = bin(score, cutpts);

do i=1 to max(r);
 idx=loc(r=i);

 group=group//i;
 freq=freq//sum(label[idx]);
end;

lbls = t( {"&amp;lt; 261" "262-273"} );
print lbls group freq;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 May 2017 13:22:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-find-frequency-of-i-in-each-bin-of-data/m-p/357877#M3473</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-05-11T13:22:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to find frequency of i in each bin of data?</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-find-frequency-of-i-in-each-bin-of-data/m-p/358649#M3474</link>
      <description>Hi Rick your solution also worked for me. Thanks&lt;BR /&gt;</description>
      <pubDate>Mon, 15 May 2017 05:58:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-find-frequency-of-i-in-each-bin-of-data/m-p/358649#M3474</guid>
      <dc:creator>ervinodsingh</dc:creator>
      <dc:date>2017-05-15T05:58:11Z</dc:date>
    </item>
  </channel>
</rss>

