<?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: Calculating the sume of differences based conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculating-the-sum-of-differences-based-conditions/m-p/764734#M242236</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;So sorry for poor explanation!&lt;/P&gt;&lt;P&gt;This is the result that I want to have! The column DIF records the sum of difference between companies and their rivals who has higher values of VAR1. For example, Company 002 is the best in industry 4 (highest values of VAR1 in each year), thus I don't consider the differences in Var between 002 and other companies in industry 4 (001 and 003). Therefore, DIF of 002 is 0. Company 004 does not have rivals in industry 5, therefore DIF is 0 as well. Company 001 has only 1 "better" rival (higher&amp;nbsp; value of VAR1) in industry 4, which is 002, therefore DIF records the difference in VAR1 between 001 and 002. Meanwhile, 003 has two "better" rivals in industry 4, thus&amp;nbsp;therefore DIF records the THE SUM of differences in VAR1 between 001 and 003, and between 002 and 003.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 715px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/63129iFBC67A8ECB01EE4F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 29 Aug 2021 16:15:10 GMT</pubDate>
    <dc:creator>RomanLi</dc:creator>
    <dc:date>2021-08-29T16:15:10Z</dc:date>
    <item>
      <title>Calculating the sum of differences based conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-the-sum-of-differences-based-conditions/m-p/764673#M242225</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I am struggling to calculate the sum of differences between variables based on conditions. For instance, I have this data:&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 597px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/63106i7FBC9F88B105AE02/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;What I want to see is the sum of difference in var1 between companies in the same industry, but only considers rivals who has higher value of var1. For instance, for company 001, in 2015, it has two rivals (002 and 003) in industry 4, but I only consider 002 because 003 has lower value of var1. Therefore, the difference should be 30-25=5. The same for other companies in difference years and industries.&amp;nbsp;&lt;BR /&gt;Please help me which statement that I should go through!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much for your reading,&lt;/P&gt;
&lt;P&gt;Roman&lt;/P&gt;</description>
      <pubDate>Sun, 29 Aug 2021 16:26:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-the-sum-of-differences-based-conditions/m-p/764673#M242225</guid>
      <dc:creator>RomanLi</dc:creator>
      <dc:date>2021-08-29T16:26:45Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating the sume of differences based conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-the-sum-of-differences-based-conditions/m-p/764675#M242227</link>
      <description>&lt;P&gt;Show us the desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, you have explained what to do for company 1, but its not clear to me what you should do for the other companies, and for years that don't match across companies.&lt;/P&gt;</description>
      <pubDate>Sun, 29 Aug 2021 14:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-the-sum-of-differences-based-conditions/m-p/764675#M242227</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-29T14:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating the sume of differences based conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-the-sum-of-differences-based-conditions/m-p/764676#M242228</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you provide us with the data in data step format?&lt;/P&gt;
&lt;P&gt;Paste your code in the window that pops-up after clicking the "Insert SAS Code" icon on the toolbar (the little running man).&lt;/P&gt;
&lt;P&gt;We cannot code against a picture.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sun, 29 Aug 2021 14:10:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-the-sum-of-differences-based-conditions/m-p/764676#M242228</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-08-29T14:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating the sume of differences based conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-the-sum-of-differences-based-conditions/m-p/764734#M242236</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;So sorry for poor explanation!&lt;/P&gt;&lt;P&gt;This is the result that I want to have! The column DIF records the sum of difference between companies and their rivals who has higher values of VAR1. For example, Company 002 is the best in industry 4 (highest values of VAR1 in each year), thus I don't consider the differences in Var between 002 and other companies in industry 4 (001 and 003). Therefore, DIF of 002 is 0. Company 004 does not have rivals in industry 5, therefore DIF is 0 as well. Company 001 has only 1 "better" rival (higher&amp;nbsp; value of VAR1) in industry 4, which is 002, therefore DIF records the difference in VAR1 between 001 and 002. Meanwhile, 003 has two "better" rivals in industry 4, thus&amp;nbsp;therefore DIF records the THE SUM of differences in VAR1 between 001 and 003, and between 002 and 003.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 715px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/63129iFBC67A8ECB01EE4F/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 29 Aug 2021 16:15:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-the-sum-of-differences-based-conditions/m-p/764734#M242236</guid>
      <dc:creator>RomanLi</dc:creator>
      <dc:date>2021-08-29T16:15:10Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating the sume of differences based conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-the-sum-of-differences-based-conditions/m-p/764735#M242237</link>
      <description>&lt;P&gt;Hello Koen,&lt;/P&gt;&lt;P&gt;So sorry because I am new the platform. This is the data:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID Year Ind Var1;
datalines;
001	2015	4	25
001	2016	4	15
001	2017	4	18
001	2018	4	17
002	2015	4	30
002	2016	4	45
002	2017	4	72
002	2018	4	11
003	2015	4	10
003	2016	4	9
003	2017	4	5
003	2018	4	4
004	2015	5	40
004	2016	5	50
004	2017	5	60
004	2018	5	70;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Could I mind you see the previous comments about my "want" data for detailed explaination.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much!&lt;/P&gt;&lt;P&gt;Roman,&lt;/P&gt;</description>
      <pubDate>Sun, 29 Aug 2021 16:25:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-the-sum-of-differences-based-conditions/m-p/764735#M242237</guid>
      <dc:creator>RomanLi</dc:creator>
      <dc:date>2021-08-29T16:25:17Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating the sume of differences based conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-the-sum-of-differences-based-conditions/m-p/764736#M242238</link>
      <description>&lt;P&gt;Hello &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/395255"&gt;@RomanLi&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's a small error in your data-step.&lt;/P&gt;
&lt;P&gt;The semi-colon to terminate the data portion should not be on the last data-line but just below.&lt;/P&gt;
&lt;P&gt;Like here:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID Year Ind Var1;
datalines;
001	2015	4	25
001	2016	4	15
001	2017	4	18
001	2018	4	17
002	2015	4	30
002	2016	4	45
002	2017	4	72
002	2018	4	11
003	2015	4	10
003	2016	4	9
003	2017	4	5
003	2018	4	4
004	2015	5	40
004	2016	5	50
004	2017	5	60
004	2018	5	70
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have also noticed your better explanation to &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;If not answered by tomorrow by someone else, I will write the program for you.&lt;/P&gt;
&lt;P&gt;It's Sunday-evening-dinner-time here in Western Europe.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sun, 29 Aug 2021 16:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-the-sum-of-differences-based-conditions/m-p/764736#M242238</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-08-29T16:41:24Z</dc:date>
    </item>
  </channel>
</rss>

