<?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 get a value from this year minus last year. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-value-from-this-year-minus-last-year/m-p/335779#M76037</link>
    <description>&lt;P&gt;So that's really all that is involved? &amp;nbsp;No third variable like COUNTRY? &amp;nbsp;If you are only concerned with that single difference, here is a way to add it onto the final observation:&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 year;&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 end=done;&lt;/P&gt;
&lt;P&gt;deficit_diff = diff(deficit);&lt;/P&gt;
&lt;P&gt;if done=0 then deficit_diff=.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This program calculates the deficit difference on every pair of observations, then wipes out the calculated value for all but the final pair of years.&lt;/P&gt;</description>
    <pubDate>Fri, 24 Feb 2017 22:01:48 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-02-24T22:01:48Z</dc:date>
    <item>
      <title>How to get a value from this year minus last year.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-value-from-this-year-minus-last-year/m-p/335624#M76001</link>
      <description>&lt;P&gt;I have a data set that calculates trade deficit in various years. I need to calculate the trade deficit between the last year of the data set and the second to last year of the data set. Please advise,&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 15:54:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-value-from-this-year-minus-last-year/m-p/335624#M76001</guid>
      <dc:creator>pacruz</dc:creator>
      <dc:date>2017-02-24T15:54:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a value from this year minus last year.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-value-from-this-year-minus-last-year/m-p/335629#M76003</link>
      <description>&lt;P&gt;Please provide a sample of the dataset preferably in data step code form&amp;nbsp;that we can run. generate&amp;nbsp;and then try out a solution for you.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 15:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-value-from-this-year-minus-last-year/m-p/335629#M76003</guid>
      <dc:creator>nehalsanghvi</dc:creator>
      <dc:date>2017-02-24T15:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a value from this year minus last year.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-value-from-this-year-minus-last-year/m-p/335635#M76007</link>
      <description>&lt;P&gt;YRDIFF() function can get years between 2 dates. &amp;nbsp;If you want good answers then provide the required information, we can't see anything about what your tring to do, so post test data in the form of a datastep and required output and any other information.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 16:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-value-from-this-year-minus-last-year/m-p/335635#M76007</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-02-24T16:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a value from this year minus last year.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-value-from-this-year-minus-last-year/m-p/335647#M76011</link>
      <description>&lt;P&gt;If you just need to calculate the change (delta) of the most recent two years of your data per company, then you could use something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
  set sashelp.class (rename=(sex=company height=deficit weight=year));
run;

proc sort data=have;
  by company  descending year;
run;

data want (keep=company delta);
  set have;
  by company;
  retain hold_deficit;
  if first.company then do;
    counter=1;
    hold_deficit=deficit;
  end;
  else do;
    counter+1;
    if counter eq 2 then do;
      delta=hold_deficit/deficit-1;
      output;
    end;
  end;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 16:31:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-value-from-this-year-minus-last-year/m-p/335647#M76011</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-02-24T16:31:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a value from this year minus last year.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-value-from-this-year-minus-last-year/m-p/335651#M76013</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 16:39:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-value-from-this-year-minus-last-year/m-p/335651#M76013</guid>
      <dc:creator>pacruz</dc:creator>
      <dc:date>2017-02-24T16:39:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to get a value from this year minus last year.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-value-from-this-year-minus-last-year/m-p/335779#M76037</link>
      <description>&lt;P&gt;So that's really all that is involved? &amp;nbsp;No third variable like COUNTRY? &amp;nbsp;If you are only concerned with that single difference, here is a way to add it onto the final observation:&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 year;&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 end=done;&lt;/P&gt;
&lt;P&gt;deficit_diff = diff(deficit);&lt;/P&gt;
&lt;P&gt;if done=0 then deficit_diff=.;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This program calculates the deficit difference on every pair of observations, then wipes out the calculated value for all but the final pair of years.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Feb 2017 22:01:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-get-a-value-from-this-year-minus-last-year/m-p/335779#M76037</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-02-24T22:01:48Z</dc:date>
    </item>
  </channel>
</rss>

