<?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: Help with pulling out last data from a time period and first data from the next in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-with-pulling-out-last-data-from-a-time-period-and-first/m-p/577939#M163839</link>
    <description>&lt;P&gt;Once you understand the code above, extending it to meet your new requirement which has the same structure as the previous, will seem trivial.&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jul 2019 03:04:51 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2019-07-31T03:04:51Z</dc:date>
    <item>
      <title>Help with pulling out last data from a time period and first data from the next</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-pulling-out-last-data-from-a-time-period-and-first/m-p/577558#M163659</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am able to pull the data that I need out of the last of the first time frame and then out of the first of the second selected time by using the proc sql statement as such:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;proc sql;&lt;BR /&gt;create table x2018 as&lt;BR /&gt;select *&lt;BR /&gt;from work.completion_status&lt;BR /&gt;where Titer ne 'x' and COLLECT2018='YES'&lt;BR /&gt;group by Patient_ID&lt;BR /&gt;having Lab_1_Spec_Collection_Date= min(Lab_1_Spec_Collection_Date);&lt;BR /&gt;quit; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;proc sql;&lt;BR /&gt;create table xnot2018 as&lt;BR /&gt;select *&lt;BR /&gt;from work.completion_status&lt;BR /&gt;where Titer ne 'x' and COLLECT2018='YES'&lt;BR /&gt;group by Patient_ID&lt;BR /&gt;having Lab_1_Spec_Collection_Date= max(Lab_1_Spec_Collection_Date);&lt;BR /&gt;quit; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;However, I cannot figure out how to compare these data.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;Each of these data that are being pulled are attached to a patient ID and I want to compare an already recoded value in the first dataset to the second dataset. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;For instance PTX has their last lab value prior to 2018 in 2015 and the attached value is 1. PTX also has a 2018 lab value and the first one is 4. I want SAS to find these values and essentially calculate 1-4=(-3).&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;I want to be able to compare this among all PatientIDs.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;Thank you!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 22:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-pulling-out-last-data-from-a-time-period-and-first/m-p/577558#M163659</guid>
      <dc:creator>EdwardsL8</dc:creator>
      <dc:date>2019-07-29T22:06:21Z</dc:date>
    </item>
    <item>
      <title>Re: Help with pulling out last data from a time period and first data from the next</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-pulling-out-last-data-from-a-time-period-and-first/m-p/577562#M163661</link>
      <description>&lt;P&gt;I think you could use correlated subqueries to get this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;create table want as
select unique Patient_ID,
(   select mean(PTX)
    from completion_status
    where Patient_ID = a.Patient_ID and Titer ne 'x' and COLLECT2018='YES'
    having Lab_1_Spec_Collection_Date= min(Lab_1_Spec_Collection_Date)) - 
(   select mean(PTX)
    from completion_status
    where Patient_ID = a.Patient_ID and Titer ne 'x' and COLLECT2018='YES'
    having Lab_1_Spec_Collection_Date= min(Lab_1_Spec_Collection_Date)) as PTXdiff
from completion_status as a;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 22:50:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-pulling-out-last-data-from-a-time-period-and-first/m-p/577562#M163661</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-07-29T22:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: Help with pulling out last data from a time period and first data from the next</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-pulling-out-last-data-from-a-time-period-and-first/m-p/577928#M163830</link>
      <description>&lt;P&gt;So I have gotten closer,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but now I need to take these patient_IDs and find the difference in the dilution between these selected lab values.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What is the correct way to write the below code?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data work.import5;&lt;BR /&gt;set work.import4;&lt;BR /&gt;by Patient_ID;&lt;BR /&gt;*result= ((DILUTION where x2018='YES')-(DILUTION where xPRE2018='YES'));&lt;BR /&gt;run;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2019 00:11:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-pulling-out-last-data-from-a-time-period-and-first/m-p/577928#M163830</guid>
      <dc:creator>EdwardsL8</dc:creator>
      <dc:date>2019-07-31T00:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: Help with pulling out last data from a time period and first data from the next</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-pulling-out-last-data-from-a-time-period-and-first/m-p/577939#M163839</link>
      <description>&lt;P&gt;Once you understand the code above, extending it to meet your new requirement which has the same structure as the previous, will seem trivial.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jul 2019 03:04:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-pulling-out-last-data-from-a-time-period-and-first/m-p/577939#M163839</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-07-31T03:04:51Z</dc:date>
    </item>
  </channel>
</rss>

