<?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 convert year-by-year changes to changes relative to a base year? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-year-by-year-changes-to-changes-relative-to-a/m-p/17319#M3280</link>
    <description>Thanks. I don't have the data on hand right now. MaxW and you gave me a framework to work on. I will try it out. Whether I make it or not, I will let you guys know the outcome. &lt;BR /&gt;
&lt;BR /&gt;
In fact the data is a bit more complicated. in some cases, the Q_ratio can be 1, meaning current year's Q is the same as last years. Sometimes Q_ratio is 1 following a year of 0, then this 1 means Q is reset. Also there may be a year where Q_ratio has missing value. Very annoying. &lt;BR /&gt;
&lt;BR /&gt;
Anyway, I will be back with more questions or my code on the basis of yours. &lt;BR /&gt;
&lt;BR /&gt;
Thanks again to you and MaxW.</description>
    <pubDate>Fri, 25 Feb 2011 03:37:11 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2011-02-25T03:37:11Z</dc:date>
    <item>
      <title>How to convert year-by-year changes to changes relative to a base year?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-year-by-year-changes-to-changes-relative-to-a/m-p/17315#M3276</link>
      <description>Hi, I am not sure if this forum is the appropriate one for my question. If it's not, my apology. I searched several forums for a similar question but found none. So I am posting my question here.&lt;BR /&gt;
&lt;BR /&gt;
I have a data set that provides year-by-year changes. I want to create a new variable that takes the first year of each ID and accumulates the changes of all previous years. One factor that complicates the calculation is the year_by_year ratio may be reset to zero and then later to one. In this case, I wish the year it is reset to one is used as a new base. Also, the time-span of each ID may differ from others'. Like A's starts from 1997 but B's starts from 1995. &lt;BR /&gt;
&lt;BR /&gt;
Can someone let me know what proc or macro to use? Thanks a bunch.&lt;BR /&gt;
&lt;BR /&gt;
Below is an example:&lt;BR /&gt;
 ..ID.....YEAR.....Q_Ratio.....What_I_Need.........My.Note&lt;BR /&gt;
A...........1997.........1.02...........1.020&lt;BR /&gt;
A...........1998..........0.9...........0.918................=.9.*.1.02&lt;BR /&gt;
A...........1999.........0.88...........0.808................=.88.*..918&lt;BR /&gt;
A...........2000.........1.32...........1.066...............=.1.066.*.0.808.&lt;BR /&gt;
A...........2001.........1.11...........1.184...............etc.&lt;BR /&gt;
B...........1995............1...............1&lt;BR /&gt;
B...........1996.........1.05...........1.050&lt;BR /&gt;
B...........1997.........0.89...........0.935&lt;BR /&gt;
B...........1998............0...............0..................reset.to.zero&lt;BR /&gt;
B...........1999............1...............1..................reset.to.one&lt;BR /&gt;
B...........2000.........1.11...........1.110&lt;BR /&gt;
B...........2001.........1.21...........1.343&lt;BR /&gt;
B...........2002..........0.8...........1.074

Message was edited by: wtqn</description>
      <pubDate>Thu, 24 Feb 2011 21:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-year-by-year-changes-to-changes-relative-to-a/m-p/17315#M3276</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-24T21:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert year-by-year changes to changes relative to a base year?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-year-by-year-changes-to-changes-relative-to-a/m-p/17316#M3277</link>
      <description>You can use by-group processing and first. to perform this task:&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=temp;&lt;BR /&gt;
	by ID Year;&lt;BR /&gt;
run;&lt;BR /&gt;
Data temp;&lt;BR /&gt;
	Retain What_I_Need;&lt;BR /&gt;
	set temp;&lt;BR /&gt;
	by id year;&lt;BR /&gt;
	if first.ID or Q_Ratio in (0,1) then What_I_Need=Q_Ratio;&lt;BR /&gt;
	else What_I_Need=What_I_Need*Q_Ratio;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
The retain statements keeps the previous value of What_I_Need, unless it is reset to Q_Ratio by a new value of ID or a Q_Ratio of 0 or 1.&lt;BR /&gt;
&lt;BR /&gt;
Hope this helps.</description>
      <pubDate>Thu, 24 Feb 2011 23:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-year-by-year-changes-to-changes-relative-to-a/m-p/17316#M3277</guid>
      <dc:creator>MaxW</dc:creator>
      <dc:date>2011-02-24T23:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert year-by-year changes to changes relative to a base year?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-year-by-year-changes-to-changes-relative-to-a/m-p/17317#M3278</link>
      <description>thanks for your prompt reply. I will try it out. Best,</description>
      <pubDate>Fri, 25 Feb 2011 01:07:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-year-by-year-changes-to-changes-relative-to-a/m-p/17317#M3278</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-25T01:07:23Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert year-by-year changes to changes relative to a base year?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-year-by-year-changes-to-changes-relative-to-a/m-p/17318#M3279</link>
      <description>Hi.&lt;BR /&gt;
There is also something uncertain ,Can you post some more data as it.&lt;BR /&gt;
With my understanding , I code these:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data temp;&lt;BR /&gt;
input id $ year q_ratio  ;&lt;BR /&gt;
datalines;&lt;BR /&gt;
A 1997 1.02&lt;BR /&gt;
A 1998 0.9&lt;BR /&gt;
A 1999 0.88&lt;BR /&gt;
A 2000 1.32&lt;BR /&gt;
A 2001 1.11&lt;BR /&gt;
B 1995 1&lt;BR /&gt;
B 1996 1.05&lt;BR /&gt;
B 1997 0.89&lt;BR /&gt;
B 1998 0&lt;BR /&gt;
B 1999 1&lt;BR /&gt;
B 2000 1.11&lt;BR /&gt;
B 2001 1.21&lt;BR /&gt;
B 2002 0.8&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=temp;&lt;BR /&gt;
by ID Year;&lt;BR /&gt;
run;&lt;BR /&gt;
data want;&lt;BR /&gt;
 set temp;&lt;BR /&gt;
 retain need;&lt;BR /&gt;
 if id ne lag(id) then need=q_ratio;&lt;BR /&gt;
  else need=need*q_ratio;&lt;BR /&gt;
 if id eq lag(id) and lag(q_ratio)=0 then need=q_ratio;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp</description>
      <pubDate>Fri, 25 Feb 2011 02:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-year-by-year-changes-to-changes-relative-to-a/m-p/17318#M3279</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-02-25T02:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert year-by-year changes to changes relative to a base year?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-year-by-year-changes-to-changes-relative-to-a/m-p/17319#M3280</link>
      <description>Thanks. I don't have the data on hand right now. MaxW and you gave me a framework to work on. I will try it out. Whether I make it or not, I will let you guys know the outcome. &lt;BR /&gt;
&lt;BR /&gt;
In fact the data is a bit more complicated. in some cases, the Q_ratio can be 1, meaning current year's Q is the same as last years. Sometimes Q_ratio is 1 following a year of 0, then this 1 means Q is reset. Also there may be a year where Q_ratio has missing value. Very annoying. &lt;BR /&gt;
&lt;BR /&gt;
Anyway, I will be back with more questions or my code on the basis of yours. &lt;BR /&gt;
&lt;BR /&gt;
Thanks again to you and MaxW.</description>
      <pubDate>Fri, 25 Feb 2011 03:37:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-convert-year-by-year-changes-to-changes-relative-to-a/m-p/17319#M3280</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-25T03:37:11Z</dc:date>
    </item>
  </channel>
</rss>

