<?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 First. and Last. Variables sequence in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/First-and-Last-Variables-sequence/m-p/404530#M279064</link>
    <description>&lt;P&gt;I have the following dataset below. I have been able to subset the data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) have patients (Patient_No) with any prior positive outcome and any subsequent negative outcome,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;2) have patients with at least 1 prior positive outcome, at least 1 subsequent negative&lt;BR /&gt; outcome, at least 90 days between the first low positive or negative outcome and &lt;BR /&gt;most recent negative outcome, most recent outcome should be negative and&lt;BR /&gt; there are no subsequent positive outcomes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Diagnose;
Input @1 Patient_No $2.
@3 Date MMDDYY10.
@14 Visit_No $2.
@16 Outcome $12.;
Format Date MMDDYY10.;
Datalines;
1 10/21/2000 1 Negative
1 10/25/2000 2 Positive
1 11/01/2000 3 Negative
1 05/28/2001 4 Negative
2 11/22/2000 1 Positive
2 11/29/2000 2 Positive
2 12/28/2000 3 Positive
2 06/28/2001 4 Low positive
2 10/29/2001 5 Negative
3 12/12/2000 1 Positive
3 12/29/2000 2 Positive
3 02/21/2001 3 Positive
3 07/12/2001 4 Negative
3 08/29/2001 5 Positive
;
run;
&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have the following code. However, when the first outcome is negative as in Patient 1, the code fails to meet the rules. Instead of having 3 patients in Subset 1, I end up with 2 patients. Instead of having 2 patients in Subset 2, I end up with 1 because the code does not take into account the possibility of a negative first.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sub1 sub2;
do until(last.patient_no);
    set diagnose; by patient_no;
    select (Outcome);
        when ("Positive") do;
            if missing(firstPos) then firstPos = date;
            end;
        when ("Negative") do;
            if missing(firstNeg) then firstNeg = date;
            recentNeg = date;
            end;
        when("Low positive") do;
            if missing(firstLow) then firstLow = date;
            end;
        otherwise;
        end;
    end;

/* Subset 1 :  any prior positive outcome and any subsequent 
   negative outcome */
if firstPos &amp;lt; firstNeg 
then output sub1;

/* Subset 2 */
if
    /* at least 1  prior positive outcome */
    not missing(firstPos) and
    /* at least 1 subsequent negative outcome */
    firstPos &amp;lt; firstNeg and
    /* at least 90 days between the first low positive 
       or negative outcome and most recent negative outcome */
    intck("day", min(firstLow, firstNeg), recentNeg) &amp;gt;= 90 and
    /* most recent outcome should be negative and there are no 
       subsequent positive outcomes */
    Outcome = "Negative" 
then output sub2;

keep patient_No; /* Applies to both output datasets */
run;
&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 16 Oct 2017 21:39:09 GMT</pubDate>
    <dc:creator>nerdy2703</dc:creator>
    <dc:date>2017-10-16T21:39:09Z</dc:date>
    <item>
      <title>First. and Last. Variables sequence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-and-Last-Variables-sequence/m-p/404530#M279064</link>
      <description>&lt;P&gt;I have the following dataset below. I have been able to subset the data&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) have patients (Patient_No) with any prior positive outcome and any subsequent negative outcome,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;2) have patients with at least 1 prior positive outcome, at least 1 subsequent negative&lt;BR /&gt; outcome, at least 90 days between the first low positive or negative outcome and &lt;BR /&gt;most recent negative outcome, most recent outcome should be negative and&lt;BR /&gt; there are no subsequent positive outcomes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Diagnose;
Input @1 Patient_No $2.
@3 Date MMDDYY10.
@14 Visit_No $2.
@16 Outcome $12.;
Format Date MMDDYY10.;
Datalines;
1 10/21/2000 1 Negative
1 10/25/2000 2 Positive
1 11/01/2000 3 Negative
1 05/28/2001 4 Negative
2 11/22/2000 1 Positive
2 11/29/2000 2 Positive
2 12/28/2000 3 Positive
2 06/28/2001 4 Low positive
2 10/29/2001 5 Negative
3 12/12/2000 1 Positive
3 12/29/2000 2 Positive
3 02/21/2001 3 Positive
3 07/12/2001 4 Negative
3 08/29/2001 5 Positive
;
run;
&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have the following code. However, when the first outcome is negative as in Patient 1, the code fails to meet the rules. Instead of having 3 patients in Subset 1, I end up with 2 patients. Instead of having 2 patients in Subset 2, I end up with 1 because the code does not take into account the possibility of a negative first.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sub1 sub2;
do until(last.patient_no);
    set diagnose; by patient_no;
    select (Outcome);
        when ("Positive") do;
            if missing(firstPos) then firstPos = date;
            end;
        when ("Negative") do;
            if missing(firstNeg) then firstNeg = date;
            recentNeg = date;
            end;
        when("Low positive") do;
            if missing(firstLow) then firstLow = date;
            end;
        otherwise;
        end;
    end;

/* Subset 1 :  any prior positive outcome and any subsequent 
   negative outcome */
if firstPos &amp;lt; firstNeg 
then output sub1;

/* Subset 2 */
if
    /* at least 1  prior positive outcome */
    not missing(firstPos) and
    /* at least 1 subsequent negative outcome */
    firstPos &amp;lt; firstNeg and
    /* at least 90 days between the first low positive 
       or negative outcome and most recent negative outcome */
    intck("day", min(firstLow, firstNeg), recentNeg) &amp;gt;= 90 and
    /* most recent outcome should be negative and there are no 
       subsequent positive outcomes */
    Outcome = "Negative" 
then output sub2;

keep patient_No; /* Applies to both output datasets */
run;
&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2017 21:39:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-and-Last-Variables-sequence/m-p/404530#M279064</guid>
      <dc:creator>nerdy2703</dc:creator>
      <dc:date>2017-10-16T21:39:09Z</dc:date>
    </item>
    <item>
      <title>Re: First. and Last. Variables sequence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/First-and-Last-Variables-sequence/m-p/404574#M279065</link>
      <description>&lt;P&gt;Can you show what you are expecting as a result of your code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also please do not post explanations or descriptions of the problem in the code boxes. The lines are extremely hard to read. Use multiple code boxes if needed to separate the code bits between explantions.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2017 19:58:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/First-and-Last-Variables-sequence/m-p/404574#M279065</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-10-16T19:58:28Z</dc:date>
    </item>
  </channel>
</rss>

