<?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: compaare observations and extract deltas in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/compaare-observations-and-extract-deltas/m-p/282694#M57483</link>
    <description>&lt;P&gt;You would need to sort the data, to get those results (but in a different order).&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by segment source;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by segment;&lt;/P&gt;
&lt;P&gt;if first.segment that starting_value=revenue;&lt;/P&gt;
&lt;P&gt;retain starting_value;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;if last.segment and (first.segment=0);&lt;/P&gt;
&lt;P&gt;source='delta';&lt;/P&gt;
&lt;P&gt;revenue = revenue - starting_value;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;source='delta%';&lt;/P&gt;
&lt;P&gt;revenue = revenue/starting_value;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Jul 2016 14:32:09 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-07-07T14:32:09Z</dc:date>
    <item>
      <title>compaare observations and extract deltas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compaare-observations-and-extract-deltas/m-p/282678#M57477</link>
      <description>&lt;P&gt;Dear experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here what I have:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;data have;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;source="y_2016"; segment="a"; revenue=100; output;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;source="y_2016"; segment="b"; revenue=50; output;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;source="y_2015"; segment="a"; revenue=90; output;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;source="y_2015"; segment="b"; revenue=30; output;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;run;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;and what I want:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;data want;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;source="y_2016"; segment="a"; revenue=100; output;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;source="y_2016"; segment="b"; revenue=50; output;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;source="y_2015"; segment="a"; revenue=90; output;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;source="y_2015"; segment="b"; revenue=30; output;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;source="delta"; segment="a"; revenue=10; output;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;source="delta"; segment="b"; revenue=20; output;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;source="delta%"; segment="a"; revenue=10/90; output;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;source="delta%"; segment="b"; revenue=20/30; output;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;run;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how can I specify the calculation I want?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2016 13:29:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compaare-observations-and-extract-deltas/m-p/282678#M57477</guid>
      <dc:creator>Sir_Highbury</dc:creator>
      <dc:date>2016-07-07T13:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: compaare observations and extract deltas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compaare-observations-and-extract-deltas/m-p/282694#M57483</link>
      <description>&lt;P&gt;You would need to sort the data, to get those results (but in a different order).&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by segment source;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by segment;&lt;/P&gt;
&lt;P&gt;if first.segment that starting_value=revenue;&lt;/P&gt;
&lt;P&gt;retain starting_value;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;if last.segment and (first.segment=0);&lt;/P&gt;
&lt;P&gt;source='delta';&lt;/P&gt;
&lt;P&gt;revenue = revenue - starting_value;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;source='delta%';&lt;/P&gt;
&lt;P&gt;revenue = revenue/starting_value;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2016 14:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compaare-observations-and-extract-deltas/m-p/282694#M57483</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-07-07T14:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: compaare observations and extract deltas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compaare-observations-and-extract-deltas/m-p/282709#M57488</link>
      <description>&lt;P&gt;Dear &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding﻿&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks a lot, it fits to the case I provided my my case is a bit more complicated: I do not have only revenues but several variables and I cannot list the calculation for all of them. Anny way to automatize it? Thanks again, SH.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2016 15:18:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compaare-observations-and-extract-deltas/m-p/282709#M57488</guid>
      <dc:creator>Sir_Highbury</dc:creator>
      <dc:date>2016-07-07T15:18:11Z</dc:date>
    </item>
    <item>
      <title>Re: compaare observations and extract deltas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compaare-observations-and-extract-deltas/m-p/282711#M57489</link>
      <description>&lt;P&gt;At this point, there's too much that I would need to guess.&amp;nbsp; You'll need to show what the inputs and outputs look like when you have an additional variable.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2016 15:26:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compaare-observations-and-extract-deltas/m-p/282711#M57489</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-07-07T15:26:20Z</dc:date>
    </item>
    <item>
      <title>Re: compaare observations and extract deltas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compaare-observations-and-extract-deltas/m-p/282712#M57490</link>
      <description>&lt;P&gt;well let's assume that the input is the following one with revenue from revenue1 to revenue100.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;source="y_2016"; segment="a"; revenue1=100; revenue2=70; output;&lt;BR /&gt;source="y_2016"; segment="b"; revenue1=50; revenue2=60; output;&lt;BR /&gt;source="y_2015"; segment="a"; revenue1=90; revenue2=70; output;&lt;BR /&gt;source="y_2015"; segment="b"; revenue1=30; revenue2=700; output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output should be done in the same way, repeating the calculation for each variable. Basically I am trying to calculate difference between two tables from different years (2015 and 2016) aggregated with the same granularity (all the variables by segment).&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2016 15:48:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compaare-observations-and-extract-deltas/m-p/282712#M57490</guid>
      <dc:creator>Sir_Highbury</dc:creator>
      <dc:date>2016-07-07T15:48:17Z</dc:date>
    </item>
    <item>
      <title>Re: compaare observations and extract deltas</title>
      <link>https://communities.sas.com/t5/SAS-Programming/compaare-observations-and-extract-deltas/m-p/282718#M57492</link>
      <description>&lt;P&gt;For that sort of problem, arrays are the typical tool that lets you handle many variables.&amp;nbsp; Here would be an approach:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by segment source;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by segment;&lt;/P&gt;
&lt;P&gt;array revs {100} revenue1-revenue100;&lt;/P&gt;
&lt;P&gt;array starts {100} starting_value1-starting_value100;&lt;/P&gt;
&lt;P&gt;if first.segment then do _n_=1 to 100;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; starts{_n_} = revs{_n_};&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;retain starting_value1 - starting_value100;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;if last.segment and (first.segment=0);&lt;/P&gt;
&lt;P&gt;source='delta';&lt;/P&gt;
&lt;P&gt;do _n_=1 to 100;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; revs{_n_} = revs{_n_} - starts{_n_};&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;source='delta%';&lt;/P&gt;
&lt;P&gt;do _n_=1 to 100;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; revs{_n_} = revs{_n_} / starts{_n_};&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;output;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As you add variables, there can be silly things that happen with the data that you might want to account for.&amp;nbsp; For example, can your % be negative instead of positive?&amp;nbsp; Can the denominator be zero?&amp;nbsp; Can there be missing values in your data?&amp;nbsp; In any case, arrays let you process many variables in the same fashion without adding too much to the code.&amp;nbsp; The only burdensome part might be adding all the names of the variables to the ARRAY statement.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Jul 2016 15:51:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/compaare-observations-and-extract-deltas/m-p/282718#M57492</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-07-07T15:51:36Z</dc:date>
    </item>
  </channel>
</rss>

