<?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 count the number of positive and negative and calculate both of them(mean) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-count-the-number-of-positive-and-negative-and-calculate/m-p/841199#M332600</link>
    <description>&lt;P&gt;Seems simple enough.&amp;nbsp; What out for testing for negative.&amp;nbsp; Missing values are considered smaller than any actual value.&lt;/P&gt;
&lt;P&gt;Also you did not say which group should include the zeros, so I made them their own group.&amp;nbsp; You did not say whether or not you wanted NOBS to count the missing values or not.&amp;nbsp; I decided to exclude them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input date :yymmdd. mist ;
cards;
1996-06-20 -0.0027
1996-06-21 0.0026
1996-06-24 0.0042
1996-06-25 0.0045
1996-06-26 0.0018
1996-06-27 0.0016
1996-06-28 -0.0002
1996-07-01 0.0027
1996-07-02 0.0009
1996-07-03 -0.0005
1996-07-04 0.0070
;

proc sql ;
  create table want as 
  select year(date) as year
       , mean(mist) as mean
       , std(mist) as sd
       , sum(mist&amp;gt;0) as positive
       , sum(not (mist&amp;gt;=0)) as negative
       , mean(case when (mist&amp;gt;0) then mist end) as mean_postive
       , mean(case when (mist&amp;gt;0) then . else mist end) as mean_negative
       , count(mist) as nobs
       , sum(mist=0) as zero
       , nmiss(mist) as missing
  from have
  group by year
;
quit;
proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1666893517241.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76706iE3255A27337B07EE/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1666893517241.png" alt="Tom_0-1666893517241.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 Oct 2022 17:59:30 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-10-27T17:59:30Z</dc:date>
    <item>
      <title>how to count the number of positive and negative and calculate both of them(mean)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-count-the-number-of-positive-and-negative-and-calculate/m-p/841167#M332598</link>
      <description>&lt;P&gt;hi all,&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have&amp;nbsp;&lt;/SPAN&gt;the data&amp;nbsp;&lt;SPAN&gt;from19961/01/01 to 2014/12/31.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Below is part of my data&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Date&lt;/TD&gt;&lt;TD&gt;Mist(1)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1996-06-20&lt;/TD&gt;&lt;TD&gt;-0.0027&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1996-06-21&lt;/TD&gt;&lt;TD&gt;0.0026&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1996-06-24&lt;/TD&gt;&lt;TD&gt;0.0042&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1996-06-25&lt;/TD&gt;&lt;TD&gt;0.0045&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1996-06-26&lt;/TD&gt;&lt;TD&gt;0.0018&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1996-06-27&lt;/TD&gt;&lt;TD&gt;0.0016&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1996-06-28&lt;/TD&gt;&lt;TD&gt;-0.0002&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1996-07-01&lt;/TD&gt;&lt;TD&gt;0.0027&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1996-07-02&lt;/TD&gt;&lt;TD&gt;0.0009&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1996-07-03&lt;/TD&gt;&lt;TD&gt;-0.0005&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1996-07-04&lt;/TD&gt;&lt;TD&gt;0.0070&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;how can i output the chart like this.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="victory_2-1666883379837.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76705i6FAFD4DC616A2C3E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="victory_2-1666883379837.png" alt="victory_2-1666883379837.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks all,&lt;/P&gt;&lt;P&gt;Y&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, 27 Oct 2022 15:13:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-count-the-number-of-positive-and-negative-and-calculate/m-p/841167#M332598</guid>
      <dc:creator>victory</dc:creator>
      <dc:date>2022-10-27T15:13:37Z</dc:date>
    </item>
    <item>
      <title>Re: how to count the number of positive and negative and calculate both of them(mean)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-count-the-number-of-positive-and-negative-and-calculate/m-p/841175#M332599</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data intermediate;
    set have;
    pos_neg=sign(mist);
run;
proc summary data=intermediate;
    class date pos_neg;
    var mist;
    format date year4.;
    output out=want mean= std= n=/autoname;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code is untested as we cannot write code to work with data that is a screen capture. In the future, please provide code as working SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;instructions&lt;/A&gt;).&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 15:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-count-the-number-of-positive-and-negative-and-calculate/m-p/841175#M332599</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-27T15:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: how to count the number of positive and negative and calculate both of them(mean)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-count-the-number-of-positive-and-negative-and-calculate/m-p/841199#M332600</link>
      <description>&lt;P&gt;Seems simple enough.&amp;nbsp; What out for testing for negative.&amp;nbsp; Missing values are considered smaller than any actual value.&lt;/P&gt;
&lt;P&gt;Also you did not say which group should include the zeros, so I made them their own group.&amp;nbsp; You did not say whether or not you wanted NOBS to count the missing values or not.&amp;nbsp; I decided to exclude them.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input date :yymmdd. mist ;
cards;
1996-06-20 -0.0027
1996-06-21 0.0026
1996-06-24 0.0042
1996-06-25 0.0045
1996-06-26 0.0018
1996-06-27 0.0016
1996-06-28 -0.0002
1996-07-01 0.0027
1996-07-02 0.0009
1996-07-03 -0.0005
1996-07-04 0.0070
;

proc sql ;
  create table want as 
  select year(date) as year
       , mean(mist) as mean
       , std(mist) as sd
       , sum(mist&amp;gt;0) as positive
       , sum(not (mist&amp;gt;=0)) as negative
       , mean(case when (mist&amp;gt;0) then mist end) as mean_postive
       , mean(case when (mist&amp;gt;0) then . else mist end) as mean_negative
       , count(mist) as nobs
       , sum(mist=0) as zero
       , nmiss(mist) as missing
  from have
  group by year
;
quit;
proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1666893517241.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/76706iE3255A27337B07EE/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1666893517241.png" alt="Tom_0-1666893517241.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 Oct 2022 17:59:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-count-the-number-of-positive-and-negative-and-calculate/m-p/841199#M332600</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-27T17:59:30Z</dc:date>
    </item>
  </channel>
</rss>

