<?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: Sequence or first and last variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sequence-or-first-and-last-variable/m-p/402145#M278801</link>
    <description>Yes, it does. Thank you</description>
    <pubDate>Sun, 08 Oct 2017 04:03:25 GMT</pubDate>
    <dc:creator>nerdy2703</dc:creator>
    <dc:date>2017-10-08T04:03:25Z</dc:date>
    <item>
      <title>Sequence or first and last variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequence-or-first-and-last-variable/m-p/402136#M278797</link>
      <description>&lt;P&gt;I have the following dataset below. I have been trying to subset the data 1) have patients (Patient_No) with any prior positive outcome and any subsequent negative outcome, 2) have patients with at least 1&amp;nbsp; prior positive outcome, at least 1 subsequent negative outcome, at least 90 days between the first low positive or negative outcome and most recent negative outcome, most recent outcome should be negative and there are no subsequent positive outcomes.&amp;nbsp; I have tried using Proc sql&amp;nbsp; first and last to select the patients but the code is getting too long and messy.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data Diagnose;&lt;BR /&gt;Input @1 Patient_No $2.&lt;BR /&gt;@3 Date MMDDYY10.&lt;BR /&gt;@14 Visit_No $2.&lt;BR /&gt;@16 Outcome $12.;&lt;BR /&gt;Format Date MMDDYY10.;&lt;BR /&gt;Datalines;&lt;BR /&gt;1 10/21/2000 1 Positive&lt;BR /&gt;1 10/25/2000 2 Positive&lt;BR /&gt;1 11/01/2000 3 Negative&lt;BR /&gt;1 05/28/2001 4 Negative&lt;BR /&gt;2 11/22/2000 1 Positive&lt;BR /&gt;2 11/29/2000 2 Positive&lt;BR /&gt;2 12/28/2000 3 Positive&lt;BR /&gt;2 06/28/2001 4 Low positive&lt;BR /&gt;2 10/29/2001 5 Negative&lt;BR /&gt;3 12/12/2000 1 Positive&lt;BR /&gt;3 12/29/2000 2 Positive&lt;BR /&gt;3 02/21/2001 3 Positive&lt;BR /&gt;3 07/12/2001 4 Negative&lt;BR /&gt;3 08/29/2001 5 Positive&lt;BR /&gt;;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Oct 2017 02:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequence-or-first-and-last-variable/m-p/402136#M278797</guid>
      <dc:creator>nerdy2703</dc:creator>
      <dc:date>2017-10-08T02:29:36Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence or first and last variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequence-or-first-and-last-variable/m-p/402140#M278798</link>
      <description>Can you post the expected result dataset? This allows use to verify a suggestion before posting it.&lt;BR /&gt;&lt;BR /&gt;Your requirements are complex, so don't expect a single seven statements solution.</description>
      <pubDate>Sun, 08 Oct 2017 03:10:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequence-or-first-and-last-variable/m-p/402140#M278798</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2017-10-08T03:10:28Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence or first and last variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequence-or-first-and-last-variable/m-p/402141#M278799</link>
      <description>&lt;P&gt;Please post what you've tried, otherwise we may make suggestions that will not work for you.&lt;/P&gt;</description>
      <pubDate>Sun, 08 Oct 2017 03:13:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequence-or-first-and-last-variable/m-p/402141#M278799</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-08T03:13:34Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence or first and last variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequence-or-first-and-last-variable/m-p/402143#M278800</link>
      <description>&lt;P&gt;I hope this implements all of your rules:&lt;/P&gt;
&lt;P&gt;&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;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 08 Oct 2017 03:52:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequence-or-first-and-last-variable/m-p/402143#M278800</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-10-08T03:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence or first and last variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequence-or-first-and-last-variable/m-p/402145#M278801</link>
      <description>Yes, it does. Thank you</description>
      <pubDate>Sun, 08 Oct 2017 04:03:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequence-or-first-and-last-variable/m-p/402145#M278801</guid>
      <dc:creator>nerdy2703</dc:creator>
      <dc:date>2017-10-08T04:03:25Z</dc:date>
    </item>
    <item>
      <title>Re: Sequence or first and last variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sequence-or-first-and-last-variable/m-p/412786#M278802</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;, the code works fine, but I noticed that if the first visit is a negative, the code fails to meet the rules. For example, in the data set below. Patient 4 meets the rules, but has a negative first visit.&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 Positive
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
4 10/21/2000 1 Negative
4 11/25/2001 2 Positive
4 12/01/2001 3 Positive
4 06/28/2002 4 Negative
4 10/26/2002 5 Negative
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Nov 2017 03:34:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sequence-or-first-and-last-variable/m-p/412786#M278802</guid>
      <dc:creator>nerdy2703</dc:creator>
      <dc:date>2017-11-13T03:34:24Z</dc:date>
    </item>
  </channel>
</rss>

