<?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 Count data in arrays after setting conditions in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Count-data-in-arrays-after-setting-conditions/m-p/501360#M491</link>
    <description>&lt;P&gt;I have a set of data that looks like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ID  Status31Jan2007 Status28Jan2007 Status31Mar2007
001                        0               0             
002        1               0               0
003        1               1               0&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to get results like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ID       Flag1           Flag2           Flag3 
001        N               N               N            
002        Y               N               N
003        Y               Y               N&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The logic is, if as at Status31Jan2007 = 1 and the following two months, count of Status fields with 0 &amp;gt; 0, then flag it as 'Y'. Else, N.&lt;/P&gt;&lt;P&gt;Note that I have up to 118 months in my dataset.&lt;/P&gt;&lt;P&gt;After getting the results, how do I count the number of flags N and Y under each fields?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;        Count1           Count2          Count3
N          1               2               3 
Y          2               1               0&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Would appreciate the help as I am new to SAS. Thanks.&lt;/P&gt;</description>
    <pubDate>Thu, 04 Oct 2018 07:37:23 GMT</pubDate>
    <dc:creator>jshingwng</dc:creator>
    <dc:date>2018-10-04T07:37:23Z</dc:date>
    <item>
      <title>Count data in arrays after setting conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-data-in-arrays-after-setting-conditions/m-p/501360#M491</link>
      <description>&lt;P&gt;I have a set of data that looks like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ID  Status31Jan2007 Status28Jan2007 Status31Mar2007
001                        0               0             
002        1               0               0
003        1               1               0&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want to get results like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;ID       Flag1           Flag2           Flag3 
001        N               N               N            
002        Y               N               N
003        Y               Y               N&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The logic is, if as at Status31Jan2007 = 1 and the following two months, count of Status fields with 0 &amp;gt; 0, then flag it as 'Y'. Else, N.&lt;/P&gt;&lt;P&gt;Note that I have up to 118 months in my dataset.&lt;/P&gt;&lt;P&gt;After getting the results, how do I count the number of flags N and Y under each fields?&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;        Count1           Count2          Count3
N          1               2               3 
Y          2               1               0&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Would appreciate the help as I am new to SAS. Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 07:37:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-data-in-arrays-after-setting-conditions/m-p/501360#M491</guid>
      <dc:creator>jshingwng</dc:creator>
      <dc:date>2018-10-04T07:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: Count data in arrays after setting conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-data-in-arrays-after-setting-conditions/m-p/501363#M492</link>
      <description>&lt;P&gt;You can use proc freq to get counts of flags in the dataset, examples on the manual:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/statug/63962/HTML/default/viewer.htm#statug_freq_sect006.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/statug/63962/HTML/default/viewer.htm#statug_freq_sect006.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I would say is that it isn't a good idea to work with transposed data like that, its an Excel way of thinking which isn't conducive to SAS programming.&lt;/P&gt;
&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DATE&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;STATUS&lt;/P&gt;
&lt;P&gt;001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;28Jan2007&amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;31mar2007&amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;31jan2017&amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;002&amp;nbsp; &amp;nbsp;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will note that due to this structure you also save disk space as the missing is not needed.&amp;nbsp; From this you can also sum and group quite easily to get your flags.&amp;nbsp; Flag1=exists(status=1) for id, and sum(case when status=0 then 1 else 0 end)=2.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 07:42:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-data-in-arrays-after-setting-conditions/m-p/501363#M492</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-04T07:42:45Z</dc:date>
    </item>
    <item>
      <title>Re: Count data in arrays after setting conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-data-in-arrays-after-setting-conditions/m-p/501366#M493</link>
      <description>&lt;P&gt;I see. I could transpose my data from wide to long. But how would I set the condition following this&amp;nbsp;logic? --&amp;gt;&amp;nbsp;&lt;SPAN&gt;if as at Status31Jan2007 = 1 and the following two months, count of Status fields with 0 &amp;gt; 0, then flag it as 'Y'. Else, N.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How do I count the Status fields for the next 2 months as at each field?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 07:53:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-data-in-arrays-after-setting-conditions/m-p/501366#M493</guid>
      <dc:creator>jshingwng</dc:creator>
      <dc:date>2018-10-04T07:53:22Z</dc:date>
    </item>
    <item>
      <title>Re: Count data in arrays after setting conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-data-in-arrays-after-setting-conditions/m-p/501371#M495</link>
      <description>&lt;P&gt;The next two rows would be:&lt;/P&gt;
&lt;PRE&gt;left join (select sum(value) from have where date &amp;lt;= a.date &amp;lt;= intnx('month',date,2))
on   ...&lt;/PRE&gt;
&lt;P&gt;Or by datastep, its first record, then retain that, if next is within date - intnx('month',date,2) ...&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 08:13:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-data-in-arrays-after-setting-conditions/m-p/501371#M495</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-04T08:13:06Z</dc:date>
    </item>
    <item>
      <title>Re: Count data in arrays after setting conditions</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Count-data-in-arrays-after-setting-conditions/m-p/501514#M525</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/233151"&gt;@jshingwng&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I see. I could transpose my data from wide to long. But how would I set the condition following this&amp;nbsp;logic? --&amp;gt;&amp;nbsp;&lt;SPAN&gt;if as at Status31Jan2007 = 1 and the following two months, count of Status fields with 0 &amp;gt; 0, then flag it as 'Y'. Else, N.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;How do I count the Status fields for the next 2 months as at each field?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Before transposing perhaps. But would need an actual example as this seems to have the potential to add a bunch of variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or perhaps you might be wanting some sort of Proc IML (matrix) solution. An actual concrete example worked for a small number of records and variables would help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Oct 2018 14:57:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Count-data-in-arrays-after-setting-conditions/m-p/501514#M525</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-04T14:57:33Z</dc:date>
    </item>
  </channel>
</rss>

