<?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: To calculate the difference of the same variable between adjacent rows of the same patient in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/To-calculate-the-difference-of-the-same-variable-between/m-p/515760#M139225</link>
    <description>&lt;P&gt;You want a sequence of differences between&amp;nbsp;&amp;nbsp; systolicbp{I}-systolicbp{i-1}, where i is the observations number.&amp;nbsp;And for the first obs of each patient, you want the difference reset to missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the DIF function, which is defined as&amp;nbsp;&amp;nbsp;&amp;nbsp; DIF(x)=x-lag(X).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by patient;
  systolic_diff=dif(systolicbp);
  if first.patient then systolic_diff=.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited addition: I should have added that this program assumes there are no "holes" in the data.&amp;nbsp; I.e. each patient has a record for every time point, in sequence.&lt;/P&gt;</description>
    <pubDate>Sun, 25 Nov 2018 02:56:16 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2018-11-25T02:56:16Z</dc:date>
    <item>
      <title>To calculate the difference of the same variable between adjacent rows of the same patient</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-calculate-the-difference-of-the-same-variable-between/m-p/515755#M139221</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi Commuinity,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a Vital Signs dataset below which I want to add a column to flag the differences of&amp;nbsp;&lt;SPAN&gt;Systolic Blood Pressure from Baseline to 2 hours, 2 hours to 24 hours. 24 hours to 48 hours and 48 hours to Day 5 for every single patient in the dataset.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any ideas?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you&lt;/SPAN&gt;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Patient&lt;/TD&gt;&lt;TD&gt;Visit&lt;/TD&gt;&lt;TD&gt;Systolic Blood Pressure&lt;/TD&gt;&lt;TD&gt;Diastolic Blood Pressure&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1001&lt;/TD&gt;&lt;TD&gt;Baseline&lt;/TD&gt;&lt;TD&gt;146&lt;/TD&gt;&lt;TD&gt;82&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1001&lt;/TD&gt;&lt;TD&gt;hr2&lt;/TD&gt;&lt;TD&gt;119&lt;/TD&gt;&lt;TD&gt;59&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1001&lt;/TD&gt;&lt;TD&gt;hr24&lt;/TD&gt;&lt;TD&gt;133&lt;/TD&gt;&lt;TD&gt;71&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1001&lt;/TD&gt;&lt;TD&gt;hr48&lt;/TD&gt;&lt;TD&gt;102&lt;/TD&gt;&lt;TD&gt;51&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1001&lt;/TD&gt;&lt;TD&gt;D5&lt;/TD&gt;&lt;TD&gt;128&lt;/TD&gt;&lt;TD&gt;77&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1002&lt;/TD&gt;&lt;TD&gt;Baseline&lt;/TD&gt;&lt;TD&gt;122&lt;/TD&gt;&lt;TD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lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sun, 25 Nov 2018 01:23:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-calculate-the-difference-of-the-same-variable-between/m-p/515755#M139221</guid>
      <dc:creator>zimcom</dc:creator>
      <dc:date>2018-11-25T01:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: To calculate the difference of the same variable between adjacent rows of the same patient</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-calculate-the-difference-of-the-same-variable-between/m-p/515758#M139223</link>
      <description>&lt;P&gt;proc transform would be the tool I would use.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_prinqual_sect008.htm" target="_blank"&gt;https://support.sas.com/documentation/cdl/en/statug/63033/HTML/default/viewer.htm#statug_prinqual_sect008.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/modules/how-to-reshape-data-long-to-wide-using-proc-transpose/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then evaluate the your client across your time progression of&amp;nbsp; base, 2, 24, 48 and day5 by arraying the time intervals&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 25 Nov 2018 02:24:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-calculate-the-difference-of-the-same-variable-between/m-p/515758#M139223</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2018-11-25T02:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: To calculate the difference of the same variable between adjacent rows of the same patient</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-calculate-the-difference-of-the-same-variable-between/m-p/515760#M139225</link>
      <description>&lt;P&gt;You want a sequence of differences between&amp;nbsp;&amp;nbsp; systolicbp{I}-systolicbp{i-1}, where i is the observations number.&amp;nbsp;And for the first obs of each patient, you want the difference reset to missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use the DIF function, which is defined as&amp;nbsp;&amp;nbsp;&amp;nbsp; DIF(x)=x-lag(X).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by patient;
  systolic_diff=dif(systolicbp);
  if first.patient then systolic_diff=.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edited addition: I should have added that this program assumes there are no "holes" in the data.&amp;nbsp; I.e. each patient has a record for every time point, in sequence.&lt;/P&gt;</description>
      <pubDate>Sun, 25 Nov 2018 02:56:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-calculate-the-difference-of-the-same-variable-between/m-p/515760#M139225</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-11-25T02:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: To calculate the difference of the same variable between adjacent rows of the same patient</title>
      <link>https://communities.sas.com/t5/SAS-Programming/To-calculate-the-difference-of-the-same-variable-between/m-p/515761#M139226</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/122002"&gt;@VDD&lt;/a&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&lt;/P&gt;&lt;P&gt;Thank you both!&lt;/P&gt;</description>
      <pubDate>Sun, 25 Nov 2018 02:54:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/To-calculate-the-difference-of-the-same-variable-between/m-p/515761#M139226</guid>
      <dc:creator>zimcom</dc:creator>
      <dc:date>2018-11-25T02:54:06Z</dc:date>
    </item>
  </channel>
</rss>

