<?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: Longtitudal calculations - product, year, cost. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Longtitudal-calculations-product-year-cost/m-p/697322#M213084</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input Year	Type	$  Value dollar32.;
cards;
2020	Toyota	$ 20000	 
2019	Toyota	$ 16000	 
2018	Toyota	$ 14000	 
2017	Toyota	$ 14000	 
2020	Audi	$ 20000	 
2019	Audi	$ 18000	 
2018	Audi	$ 17000	 
2017	Audi	$ 15000
;
data want;
 do i=1 by 1 until(last.type);
  set have;
  by type notsorted;
  if first.type then first=value;
 end;
  diff=first-value;
  mean=diff/i;
  keep type diff mean;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 07 Nov 2020 10:41:33 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2020-11-07T10:41:33Z</dc:date>
    <item>
      <title>Longtitudal calculations - product, year, cost.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Longtitudal-calculations-product-year-cost/m-p/697317#M213081</link>
      <description>&lt;P&gt;I have a database which contain years, car model and annual service cost. Each car had a service cost each year along with other data.&lt;/P&gt;&lt;P&gt;I need to find out how to calculate the increase of values for each model over the years.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The database looks like this (simplified), contains about 10000 observations:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Year&lt;/TD&gt;&lt;TD&gt;Type&lt;/TD&gt;&lt;TD&gt;Value&lt;/TD&gt;&lt;TD&gt;Others&lt;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/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The results should be look like this:&lt;/P&gt;&lt;TABLE border="1"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Type&lt;/TD&gt;&lt;TD&gt;Change in $ from 2017 to 2020&lt;/TD&gt;&lt;TD&gt;Average change per year in $&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My apologies I am a beginner, unfortunately I am not even sure how to approach this problem.&lt;/P&gt;&lt;P&gt;Thank you for any help on this. I could not find anything similar to this problem here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 07 Nov 2020 08:38:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Longtitudal-calculations-product-year-cost/m-p/697317#M213081</guid>
      <dc:creator>RetiSas</dc:creator>
      <dc:date>2020-11-07T08:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: Longtitudal calculations - product, year, cost.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Longtitudal-calculations-product-year-cost/m-p/697318#M213082</link>
      <description>&lt;P&gt;Sort by type and year.&lt;/P&gt;
&lt;P&gt;In a data step with&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;by type;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;retain a variable for first_value. Set this value at first.type or when year = 2017 is encountered. At last.type, or when year = 2020 is encountered, do the calculations and OUTPUT.&lt;/P&gt;</description>
      <pubDate>Sat, 07 Nov 2020 09:28:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Longtitudal-calculations-product-year-cost/m-p/697318#M213082</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-07T09:28:18Z</dc:date>
    </item>
    <item>
      <title>Re: Longtitudal calculations - product, year, cost.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Longtitudal-calculations-product-year-cost/m-p/697322#M213084</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards expandtabs truncover;
input Year	Type	$  Value dollar32.;
cards;
2020	Toyota	$ 20000	 
2019	Toyota	$ 16000	 
2018	Toyota	$ 14000	 
2017	Toyota	$ 14000	 
2020	Audi	$ 20000	 
2019	Audi	$ 18000	 
2018	Audi	$ 17000	 
2017	Audi	$ 15000
;
data want;
 do i=1 by 1 until(last.type);
  set have;
  by type notsorted;
  if first.type then first=value;
 end;
  diff=first-value;
  mean=diff/i;
  keep type diff mean;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 07 Nov 2020 10:41:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Longtitudal-calculations-product-year-cost/m-p/697322#M213084</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-11-07T10:41:33Z</dc:date>
    </item>
  </channel>
</rss>

