<?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 How to count the number of occurrences in rows? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-number-of-occurrences-in-rows/m-p/671766#M36496</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;My task is to identify clients who spread the payment over time. If the event occurs, the value is 1, otherwise 0. I'm working in SAS guide so I prefer solution in query builder. I got example data table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Customer MAY JUNE JULY Target&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 200&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 300&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I achieve this?&lt;/P&gt;</description>
    <pubDate>Thu, 23 Jul 2020 11:14:05 GMT</pubDate>
    <dc:creator>PatrykSAS</dc:creator>
    <dc:date>2020-07-23T11:14:05Z</dc:date>
    <item>
      <title>How to count the number of occurrences in rows?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-number-of-occurrences-in-rows/m-p/671766#M36496</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;My task is to identify clients who spread the payment over time. If the event occurs, the value is 1, otherwise 0. I'm working in SAS guide so I prefer solution in query builder. I got example data table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Customer MAY JUNE JULY Target&lt;/P&gt;&lt;P&gt;A&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 100&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 200&amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;B&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 300&amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I achieve this?&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 11:14:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-number-of-occurrences-in-rows/m-p/671766#M36496</guid>
      <dc:creator>PatrykSAS</dc:creator>
      <dc:date>2020-07-23T11:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of occurrences in rows?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-number-of-occurrences-in-rows/m-p/671770#M36497</link>
      <description>&lt;P&gt;simple task for array,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Customer $ MAY JUNE JULY;
cards;
A              100    0        200 
B              300    0        0   
;
run;

data want;
  set have;
  array months MAY JUNE JULY;
  target =0;
  do over months; 
    target + (months &amp;gt; 0);
  end;
  target = (target &amp;gt; 1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but I would suggest to keep data in "long" format:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have_long;
input Customer $ months $ amount;
cards;
A MAY 100
A JUNE 0
A JULY 200
B MAY 300
B JUNE 0
B JULY 0
;
run;

proc sql;
  select Customer, 
  case when sum(amount &amp;gt; 0) &amp;gt; 1 then 1
                                else 0
  enD as target
  from
    have_long
  group by 
    Customer
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 11:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-number-of-occurrences-in-rows/m-p/671770#M36497</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-07-23T11:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of occurrences in rows?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-number-of-occurrences-in-rows/m-p/671772#M36498</link>
      <description>&lt;P&gt;If you want to do this in the query builder, you have to transpose first.&lt;/P&gt;
&lt;P&gt;Otherwise you need a manually written data step with array processing, as shown by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 11:36:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-number-of-occurrences-in-rows/m-p/671772#M36498</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-23T11:36:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of occurrences in rows?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-number-of-occurrences-in-rows/m-p/671893#M36503</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/315439"&gt;@PatrykSAS&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would a single numeric expression be more amenable to the Query Builder? (I don't know as I don't use EG.) If so, you could try something like this:&lt;/P&gt;
&lt;PRE&gt;target=&lt;STRONG&gt;largest(2, of may--july)&amp;gt;0&lt;/STRONG&gt;;&lt;/PRE&gt;
&lt;P&gt;Note that the inequality is equivalent to "There are at least two positive numbers among the values of the variables in the &lt;A href="https://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0wphcpsfgx6o7n1sjtqzizp1n39.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en#p1cr0027z6qx4an1maoh0fyizqtt" target="_blank" rel="noopener"&gt;name range list&lt;/A&gt; &lt;FONT face="courier new,courier"&gt;may--july&lt;/FONT&gt;&amp;nbsp;in the current observation."&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 17:12:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-number-of-occurrences-in-rows/m-p/671893#M36503</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-07-23T17:12:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of occurrences in rows?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-number-of-occurrences-in-rows/m-p/671897#M36505</link>
      <description>&lt;P&gt;The query builder uses SQL, which does not support the use of OF in a function, so you would still need to write all columns separately.&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jul 2020 17:20:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-number-of-occurrences-in-rows/m-p/671897#M36505</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-23T17:20:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to count the number of occurrences in rows?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-number-of-occurrences-in-rows/m-p/672246#M36528</link>
      <description>&lt;P&gt;Using the "point and click" facilities takes several steps, but each one is fairly easy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. First, sort by Customer (needed for the transpose).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Then run a Data -&amp;gt; Transpose that has Customer as the "Group Analysis By" variable, and all of the other variables as the transpose variables. The result should look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="197"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="67"&gt;Customer&lt;/TD&gt;
&lt;TD width="68"&gt;NAME OF FORMER VARIABLE&lt;/TD&gt;
&lt;TD width="62"&gt;Column1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD&gt;MAY&lt;/TD&gt;
&lt;TD&gt;100&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD&gt;JUNE&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD&gt;JULY&lt;/TD&gt;
&lt;TD&gt;200&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;B&lt;/TD&gt;
&lt;TD&gt;MAY&lt;/TD&gt;
&lt;TD&gt;300&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;B&lt;/TD&gt;
&lt;TD&gt;JUNE&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;B&lt;/TD&gt;
&lt;TD&gt;JULY&lt;/TD&gt;
&lt;TD&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Now, run a query to select only the rows where Column1 is greater than zero (get rid of your zero values).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4. Finally, you can either use a query that counts the number of records for each customer, or use Describe -&amp;gt; Summary Statistics to find the customers that have count 1, or greater than 1.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jul 2020 23:32:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-count-the-number-of-occurrences-in-rows/m-p/672246#M36528</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2020-07-24T23:32:10Z</dc:date>
    </item>
  </channel>
</rss>

