<?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: Percent Change Indicator Variable with Date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Percent-Change-Indicator-Variable-with-Date/m-p/633499#M187925</link>
    <description>&lt;P&gt;Since you want to compare with the&amp;nbsp;&lt;EM&gt;first&lt;/EM&gt; visit of a subject, and not with the&amp;nbsp;&lt;EM&gt;previous&lt;/EM&gt;, you need to retain a variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set myfold.t25changeshort;
by usubjid;
retain baseline;
if first.usubjid
then do;
  baseline = walktime;
  percentchange = 0;
  changed = 0;
end;
else do;
  percentchange = (walktime - baseline) / baseline;
  changed = (abs(percentchange) &amp;gt; .02);
end;
drop baseline;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you only want to show&amp;nbsp;&lt;EM&gt;increases&lt;/EM&gt; as changed, remove the abs() function.&lt;/P&gt;</description>
    <pubDate>Fri, 20 Mar 2020 08:33:28 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-03-20T08:33:28Z</dc:date>
    <item>
      <title>Percent Change Indicator Variable with Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-Change-Indicator-Variable-with-Date/m-p/633438#M187905</link>
      <description>&lt;P&gt;Hello - I have created a simple clinical dataset in long form with subjects, day of measurement, and measurement values.&amp;nbsp; I am trying to create a variable indicating percent change from the baseline (first) visit for each subsequent visit.&amp;nbsp; Based on trolling the boards, I came up with the following, but this only gives me the change between time intervals and when I try to adapt it to measure each study measurement compared to baseline, I can't seem to avoid divide by zero errors since the baseline (first observation) will of course not have a change.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached the data I have and the data I want. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; In the end, I only need one row per USUBJID, not the broad form that the code below gives me.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any recommendations are very much appreciated.&amp;nbsp; Thank you!&lt;/P&gt;&lt;P&gt;Anissa&lt;BR /&gt;&lt;BR /&gt;data walk;&lt;BR /&gt;set msoac.t25changeshort;&lt;BR /&gt;by usubjid notsorted;&lt;BR /&gt;prevwalk=lag(walktime);&lt;BR /&gt;if not first.usubjid then percentchange=(walktime-prevwalk)/prevwalk;&lt;BR /&gt;if percentchange&amp;gt;.2 then changed=1;&lt;BR /&gt;else changed=0;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 21:06:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-Change-Indicator-Variable-with-Date/m-p/633438#M187905</guid>
      <dc:creator>anissak1</dc:creator>
      <dc:date>2020-03-19T21:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: Percent Change Indicator Variable with Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-Change-Indicator-Variable-with-Date/m-p/633450#M187910</link>
      <description>&lt;P&gt;I hope you are trawling these pages rather than trolling.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can avoid a division by zero by using the divide function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WALK;
  retain BASELINE;
  set MSOAC.T25CHANGESHORT;
  by USUBJID notsorted;
  if first.USUBJID then BASELINE=WALKTIME;
  else PERCENTCHANGE=(WALKTIME-BASELINE)/BASELINE;
  CHANGED = ( PERCENTCHANGE &amp;gt; .2 );
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Mar 2020 22:52:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-Change-Indicator-Variable-with-Date/m-p/633450#M187910</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-03-19T22:52:30Z</dc:date>
    </item>
    <item>
      <title>Re: Percent Change Indicator Variable with Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-Change-Indicator-Variable-with-Date/m-p/633499#M187925</link>
      <description>&lt;P&gt;Since you want to compare with the&amp;nbsp;&lt;EM&gt;first&lt;/EM&gt; visit of a subject, and not with the&amp;nbsp;&lt;EM&gt;previous&lt;/EM&gt;, you need to retain a variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set myfold.t25changeshort;
by usubjid;
retain baseline;
if first.usubjid
then do;
  baseline = walktime;
  percentchange = 0;
  changed = 0;
end;
else do;
  percentchange = (walktime - baseline) / baseline;
  changed = (abs(percentchange) &amp;gt; .02);
end;
drop baseline;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you only want to show&amp;nbsp;&lt;EM&gt;increases&lt;/EM&gt; as changed, remove the abs() function.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Mar 2020 08:33:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-Change-Indicator-Variable-with-Date/m-p/633499#M187925</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-20T08:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: Percent Change Indicator Variable with Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-Change-Indicator-Variable-with-Date/m-p/633717#M188005</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;&amp;nbsp;and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;!&amp;nbsp; My code is clunky, but built off of yours and seems to work, and I think I am set for the moment!!&amp;nbsp; Much appreciation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best wishes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anissa&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set msoac.clean25ave;&lt;BR /&gt;retain BASELINE;&lt;BR /&gt;set MSOAC.clean25ave;&lt;BR /&gt;by USUBJID notsorted;&lt;BR /&gt;if first.USUBJID then BASELINE=WALKTIME;&lt;BR /&gt;else PERCENTCHANGE=(WALKTIME-BASELINE)/BASELINE;&lt;BR /&gt;CHANGED = ( PERCENTCHANGE &amp;gt; .2 );&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want2;&lt;BR /&gt;set want;&lt;BR /&gt;if changed=1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=want2;&lt;BR /&gt;by usubjid studyday;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want3;&lt;BR /&gt;set want2;&lt;BR /&gt;by usubjid;&lt;BR /&gt;changeday=studyday;&lt;BR /&gt;drop studyday walktime changed;&lt;BR /&gt;if first.usubjid then output want3;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Mar 2020 18:40:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-Change-Indicator-Variable-with-Date/m-p/633717#M188005</guid>
      <dc:creator>anissak1</dc:creator>
      <dc:date>2020-03-20T18:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: Percent Change Indicator Variable with Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Percent-Change-Indicator-Variable-with-Date/m-p/633719#M188006</link>
      <description>&lt;P&gt;I had to look up definitions - and think that I was both trolling and trawling...&lt;BR /&gt;Desperate times, desperate measures. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Mar 2020 18:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Percent-Change-Indicator-Variable-with-Date/m-p/633719#M188006</guid>
      <dc:creator>anissak1</dc:creator>
      <dc:date>2020-03-20T18:44:26Z</dc:date>
    </item>
  </channel>
</rss>

