<?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: calculate difference and percentage of difference based on a large dataset in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/calculate-difference-and-percentage-of-difference-based-on-a/m-p/579330#M13443</link>
    <description>&lt;P&gt;hello,&lt;/P&gt;&lt;P&gt;thank you for your answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had to take some time to read the documentation and adapt the suggested code to my real data, but it worked perfectly.&lt;/P&gt;&lt;P&gt;Thanks a lot for your help,&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;PY&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 06 Aug 2019 11:56:44 GMT</pubDate>
    <dc:creator>PierreYvesILY</dc:creator>
    <dc:date>2019-08-06T11:56:44Z</dc:date>
    <item>
      <title>calculate difference and percentage of difference based on a large dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/calculate-difference-and-percentage-of-difference-based-on-a/m-p/578753#M13384</link>
      <description>&lt;P&gt;hallo,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the following table:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="table1.PNG" style="width: 318px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/31475iE892173DA706F23B/image-size/large?v=v2&amp;amp;px=999" role="button" title="table1.PNG" alt="table1.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;and I want to obtain the following one:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="table2.PNG" style="width: 542px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/31476iC142D665A3EC55AC/image-size/large?v=v2&amp;amp;px=999" role="button" title="table2.PNG" alt="table2.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;where :&lt;/P&gt;&lt;P&gt;Delta 19/18 is the difference of the Prod values between the 2 years&amp;nbsp;by structure and month.&lt;/P&gt;&lt;P&gt;Evolution in Percent 19/18 &amp;nbsp;is the&amp;nbsp;%age change&amp;nbsp;of the Prod values between the 2 years&amp;nbsp;by structure and month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I programm this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your help.&lt;/P&gt;&lt;P&gt;PY&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2019 15:29:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/calculate-difference-and-percentage-of-difference-based-on-a/m-p/578753#M13384</guid>
      <dc:creator>PierreYvesILY</dc:creator>
      <dc:date>2019-08-02T15:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference and percentage of difference based on a large dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/calculate-difference-and-percentage-of-difference-based-on-a/m-p/578755#M13385</link>
      <description>&lt;P&gt;We need to have your sample data provided as a SAS data step, following this method:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2019 15:34:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/calculate-difference-and-percentage-of-difference-based-on-a/m-p/578755#M13385</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-08-02T15:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference and percentage of difference based on a large dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/calculate-difference-and-percentage-of-difference-based-on-a/m-p/578760#M13386</link>
      <description>&lt;P&gt;I can spend lots of time writing specific calculations but that is not the way computers really should work. There needs to be generic rules for how to combine things.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance, what &lt;STRONG&gt;in the data&lt;/STRONG&gt; tells me that the order should be value7-value8-value5 and not value5-value8-value7 or value5-value7-value8 or any of the other permutations of those 3 values.&amp;nbsp; I can see that all of the values come from the same value of month and structure&amp;nbsp;but is the YEAR involved? If so describe exactly how. And even that does not tell use that the order should be value8-value5 instead of value5-value8 for the 2018 values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And why is BBB for month2 Value3+Value6 when for AAA everything appeared to be minus.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are missing LOTS of rules as to how to calculate what you might want.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2019 15:46:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/calculate-difference-and-percentage-of-difference-based-on-a/m-p/578760#M13386</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-02T15:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference and percentage of difference based on a large dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/calculate-difference-and-percentage-of-difference-based-on-a/m-p/578765#M13388</link>
      <description>&lt;P&gt;hi Paige,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here's the original dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Beispiel(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;label&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'Beispiel'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Year:&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;8.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; Month:&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; Structure:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$35.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Prod:&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;8.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;; &lt;/FONT&gt;&lt;FONT color="#008000" face="Courier New" size="3"&gt;/* Prod is a numeric value, actually */&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2018 1 AAA 100&lt;/P&gt;&lt;P&gt;2019 1 AAA 110&lt;/P&gt;&lt;P&gt;2019 2 BBB 120&lt;/P&gt;&lt;P&gt;2018 2 AAA 250&lt;/P&gt;&lt;P&gt;2018 3 AAA 260&lt;/P&gt;&lt;P&gt;2019 2 BBB 270&lt;/P&gt;&lt;P&gt;2019 3 AAA 370&lt;/P&gt;&lt;P&gt;2018 3 AAA 380&lt;/P&gt;&lt;P&gt;2019 5 BBB 490&lt;/P&gt;&lt;P&gt;2018 4 AAA 410&lt;/P&gt;&lt;P&gt;2019 6 AAA 511&lt;/P&gt;&lt;P&gt;2019 5 BBB 612&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2019 16:01:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/calculate-difference-and-percentage-of-difference-based-on-a/m-p/578765#M13388</guid>
      <dc:creator>PierreYvesILY</dc:creator>
      <dc:date>2019-08-02T16:01:08Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference and percentage of difference based on a large dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/calculate-difference-and-percentage-of-difference-based-on-a/m-p/578766#M13389</link>
      <description>&lt;P&gt;the formula is:&lt;/P&gt;&lt;P&gt;- select month then structure&lt;/P&gt;&lt;P&gt;- then do:&lt;/P&gt;&lt;P&gt;&amp;nbsp;Delta =sum(values of 2019)&amp;nbsp;- sum(values of 2018)&lt;/P&gt;&lt;P&gt;- then do:&lt;/P&gt;&lt;P&gt;EvolPercent = 100*Delta / sum(values of 2018)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope it sets the problem in a more easy way to understand.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;regards,&lt;/P&gt;&lt;P&gt;PY&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2019 16:05:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/calculate-difference-and-percentage-of-difference-based-on-a/m-p/578766#M13389</guid>
      <dc:creator>PierreYvesILY</dc:creator>
      <dc:date>2019-08-02T16:05:45Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference and percentage of difference based on a large dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/calculate-difference-and-percentage-of-difference-based-on-a/m-p/578773#M13390</link>
      <description>How does month play into this? Is it a YTD Percent increase calculation or a Year over Year percent calculation. It would be very helpful if you could post the expected output from the data you included as demo data.</description>
      <pubDate>Fri, 02 Aug 2019 16:43:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/calculate-difference-and-percentage-of-difference-based-on-a/m-p/578773#M13390</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-08-02T16:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference and percentage of difference based on a large dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/calculate-difference-and-percentage-of-difference-based-on-a/m-p/578782#M13391</link>
      <description>&lt;P&gt;The calculation is a month(2019) to month(2018) comparison.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is the result dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Result;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Month:&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; Structure:&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$35.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Delta:&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;8.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; EvolPercent:&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;8.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 AAA 10 10&lt;/P&gt;&lt;P&gt;2 AAA -250 -100&lt;/P&gt;&lt;P&gt;3 AAA -270 -42.1875&lt;/P&gt;&lt;P&gt;4 AAA -410 -100&lt;/P&gt;&lt;P&gt;5 AAA 0 0&lt;/P&gt;&lt;P&gt;6 AAA 511 100&lt;/P&gt;&lt;P&gt;1 BBB 0 0&lt;/P&gt;&lt;P&gt;2 BBB 390 100&lt;/P&gt;&lt;P&gt;3 BBB 0 0&lt;/P&gt;&lt;P&gt;4 BBB 0 0&lt;/P&gt;&lt;P&gt;5 BBB 1022 100&lt;/P&gt;&lt;P&gt;6 BBB 0 0&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks a lot&lt;/P&gt;&lt;P&gt;PY&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2019 17:00:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/calculate-difference-and-percentage-of-difference-based-on-a/m-p/578782#M13391</guid>
      <dc:creator>PierreYvesILY</dc:creator>
      <dc:date>2019-08-02T17:00:32Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference and percentage of difference based on a large dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/calculate-difference-and-percentage-of-difference-based-on-a/m-p/578823#M13393</link>
      <description>&lt;P&gt;This is one way IF there are only 2 years involved. If you want to do sequential multiple years you need to say so.&lt;/P&gt;
&lt;PRE&gt;data Beispiel(label='Beispiel');
input Year:8. Month:2. Structure:$35. Prod:8.; /* Prod is a numeric value, actually */
datalines;
2018 1 AAA 100
2019 1 AAA 110
2019 2 BBB 120
2018 2 AAA 250
2018 3 AAA 260
2019 2 BBB 270
2019 3 AAA 370
2018 3 AAA 380
2019 5 BBB 490
2018 4 AAA 410
2019 6 AAA 511
2019 5 BBB 612
;
run;


proc summary data=Beispiel nway;
   class structure month year ;
   var prod;
   output out=work.sums (drop= _:) sum=;
run;

proc transpose data=work.sums
    out=work.trans (drop=_name_) prefix=y;
   by structure month;
   id year;
   var prod;
run;

data work.want;
   set work.trans;
   if missing( y2018) and not missing(y2019) then do;
      delta=y2019;
      pct=100;
   end;
   else    if missing( y2019) and not missing(y2018) then do;
      delta= -1*y2018;
      pct  = -100;
   end;
   else    if missing( y2019) and missing(y2018) then do;
      delta= 0;
      pct  = 0;
   end;

   else do;
      delta = y2019-y2018;
      pct = 100 * delta/y2018;
   end;
   
run;&lt;/PRE&gt;
&lt;P&gt;I have left adding the months without any actual values as an exercise for the interested reader.&lt;/P&gt;
&lt;P&gt;This is NOT the only way, just one way. I left the individual year totals for each month so you can check the data to see if it meets your expectations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Personally, I find the concept of assigning a delta or percent change when there is only one value suspect in many ways.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2019 20:40:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/calculate-difference-and-percentage-of-difference-based-on-a/m-p/578823#M13393</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-02T20:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: calculate difference and percentage of difference based on a large dataset</title>
      <link>https://communities.sas.com/t5/New-SAS-User/calculate-difference-and-percentage-of-difference-based-on-a/m-p/579330#M13443</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;&lt;P&gt;thank you for your answer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had to take some time to read the documentation and adapt the suggested code to my real data, but it worked perfectly.&lt;/P&gt;&lt;P&gt;Thanks a lot for your help,&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;PY&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Aug 2019 11:56:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/calculate-difference-and-percentage-of-difference-based-on-a/m-p/579330#M13443</guid>
      <dc:creator>PierreYvesILY</dc:creator>
      <dc:date>2019-08-06T11:56:44Z</dc:date>
    </item>
  </channel>
</rss>

