<?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 Summing only negative values of a certain variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Summing-only-negative-values-of-a-certain-variable/m-p/52851#M14563</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Thanks for the quick and correct answers!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 02 Apr 2012 21:39:14 GMT</pubDate>
    <dc:creator>carbs</dc:creator>
    <dc:date>2012-04-02T21:39:14Z</dc:date>
    <item>
      <title>Summing only negative values of a certain variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-only-negative-values-of-a-certain-variable/m-p/52845#M14557</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have monthly data on variable x across 20 countries and would like to sum only the negative values of the variable per month. I've used the code below to sum all of the monthly observations across 20 countries together, and would like to know how to modify the code to get it to sum only the negative values.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;DIV&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;by&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; date;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; first.date &lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;then&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; total=&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;&amp;nbsp; total+x;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;if&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; last.date &lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;then&lt;/SPAN&gt; &lt;SPAN style="background-color: white; font-family: 'Courier New'; color: blue; font-size: 10pt;"&gt;output&lt;/SPAN&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: white; font-family: 'Courier New'; color: black; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt; &lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt; &lt;/STRONG&gt;&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;﻿&lt;/STRONG&gt;thanks in advance..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008080; font-size: 10pt; font-family: Courier New;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN style="font-family: Courier New; color: #000080; font-size: 10pt;"&gt;&lt;SPAN style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Apr 2012 08:58:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-only-negative-values-of-a-certain-variable/m-p/52845#M14557</guid>
      <dc:creator>carbs</dc:creator>
      <dc:date>2012-04-02T08:58:49Z</dc:date>
    </item>
    <item>
      <title>Summing only negative values of a certain variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-only-negative-values-of-a-certain-variable/m-p/52846#M14558</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Try this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;SPAN style="font-family: Courier New; color: #000080; font-size: 10pt;"&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;SPAN style="font-family: Courier New; color: #000080; font-size: 10pt;"&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;SPAN style="font-family: Courier New; color: #000080; font-size: 10pt;"&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;STRONG style=": ; color: #000080; font-size: 2; font-family: 'Courier New';"&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;SPAN style="font-family: Courier New; color: #000080; font-size: 10pt;"&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;STRONG style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;STRONG style=": ; color: #000080; font-size: 2; font-family: 'Courier New';"&gt;&lt;P&gt;&lt;/P&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style=": ; color: #000080; font-size: 2; font-family: 'Courier New';"&gt;&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN style="font-family: Courier New; color: #000080; font-size: 10pt;"&gt;&lt;SPAN style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt; &lt;/SPAN&gt;&lt;P&gt;&lt;SPAN style="font-size: 8pt;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;data have; &lt;/P&gt;&lt;P&gt;input date x; &lt;/P&gt;&lt;P&gt;cards; &lt;/P&gt;&lt;P&gt;1 3 &lt;/P&gt;&lt;P&gt;1 -3 &lt;/P&gt;&lt;P&gt;1 -4 &lt;/P&gt;&lt;P&gt;2 4 &lt;/P&gt;&lt;P&gt;2 -2 &lt;/P&gt;&lt;P&gt;2 -7 &lt;/P&gt;&lt;P&gt;; &lt;/P&gt;&lt;P&gt;run; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;set have; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;by date; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if first.date then total=0; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if x&amp;lt;0 then total+x; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if last.date then output; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN style="font-family: Courier New; color: #000080; font-size: 10pt;"&gt;&lt;SPAN style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN style="font-family: Courier New; color: #000080; font-size: 10pt;"&gt;&lt;SPAN style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008080; font-size: 10pt; font-family: Courier New;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008080; font-size: 10pt; font-family: Courier New;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;SPAN style="font-family: Courier New; color: #000080; font-size: 10pt;"&gt;&lt;SPAN style="color: #000080; font-size: 10pt; font-family: Courier New;"&gt;&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Apr 2012 09:04:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-only-negative-values-of-a-certain-variable/m-p/52846#M14558</guid>
      <dc:creator>Gerd47</dc:creator>
      <dc:date>2012-04-02T09:04:33Z</dc:date>
    </item>
    <item>
      <title>Summing only negative values of a certain variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-only-negative-values-of-a-certain-variable/m-p/52847#M14559</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Or use (where=) to make it more efficient in this case:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have(where=(x&amp;lt;0));&lt;/P&gt;&lt;P&gt;by date;&lt;/P&gt;&lt;P&gt;if x&amp;lt;0;&lt;/P&gt;&lt;P&gt;if first.date then total=0;&lt;/P&gt;&lt;P&gt;if x&amp;lt;0 then total+x;&lt;/P&gt;&lt;P&gt;if last.date then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Apr 2012 11:18:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-only-negative-values-of-a-certain-variable/m-p/52847#M14559</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-04-02T11:18:07Z</dc:date>
    </item>
    <item>
      <title>Re: Summing only negative values of a certain variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-only-negative-values-of-a-certain-variable/m-p/52848#M14560</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;more efficient:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have(where=(x&amp;lt;0));&lt;/P&gt;&lt;P&gt;by date;&lt;/P&gt;&lt;P&gt;if first.date then total=0;&lt;/P&gt;&lt;P&gt;total+x;&lt;/P&gt;&lt;P&gt;if last.date then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Apr 2012 12:17:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-only-negative-values-of-a-certain-variable/m-p/52848#M14560</guid>
      <dc:creator>Linlin</dc:creator>
      <dc:date>2012-04-02T12:17:24Z</dc:date>
    </item>
    <item>
      <title>Re: Summing only negative values of a certain variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-only-negative-values-of-a-certain-variable/m-p/52849#M14561</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;LOL, I don't know what I am doing. Guess I just added (where=) to his/her code harmlessly and more important,&amp;nbsp; effortlessly. Linlin, thanks for pointing that out.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Haikuo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Apr 2012 12:28:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-only-negative-values-of-a-certain-variable/m-p/52849#M14561</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2012-04-02T12:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: Summing only negative values of a certain variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-only-negative-values-of-a-certain-variable/m-p/52850#M14562</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't know if efficiency is a concern. I do know that the WHERE approach will &lt;STRONG&gt;not&lt;/STRONG&gt; generate an observation for a month with no negatives. That may or may not be desired.&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote"&gt;&lt;P&gt;Linlin wrote:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;more efficient:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have(where=(x&amp;lt;0));&lt;/P&gt;&lt;P&gt;by date;&lt;/P&gt;&lt;P&gt;if first.date then total=0;&lt;/P&gt;&lt;P&gt;total+x;&lt;/P&gt;&lt;P&gt;if last.date then output;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Apr 2012 20:06:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-only-negative-values-of-a-certain-variable/m-p/52850#M14562</guid>
      <dc:creator>Howles</dc:creator>
      <dc:date>2012-04-02T20:06:53Z</dc:date>
    </item>
    <item>
      <title>Summing only negative values of a certain variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Summing-only-negative-values-of-a-certain-variable/m-p/52851#M14563</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt; Thanks for the quick and correct answers!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 02 Apr 2012 21:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Summing-only-negative-values-of-a-certain-variable/m-p/52851#M14563</guid>
      <dc:creator>carbs</dc:creator>
      <dc:date>2012-04-02T21:39:14Z</dc:date>
    </item>
  </channel>
</rss>

