<?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: List of ID with multiple conditions either or in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/List-of-ID-with-multiple-conditions-either-or/m-p/667232#M199754</link>
    <description>&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Yes, I want list of distinct IDs that satisfy the conditions. One ID my have in multiple rows which will fulfill the conditions. I gave here a small portion of data my whole data set.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jul 2020 16:27:19 GMT</pubDate>
    <dc:creator>mahossain</dc:creator>
    <dc:date>2020-07-06T16:27:19Z</dc:date>
    <item>
      <title>List of ID with multiple conditions either or</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-ID-with-multiple-conditions-either-or/m-p/667201#M199733</link>
      <description>&lt;P&gt;I want to create a sub-data set with list of all variables with the following conditions:&lt;BR /&gt;if IDs (2102-202) are with TRCD =LDIAM or SAXIS then select all&amp;nbsp; IDs (2102-202) with SAXIS only&amp;nbsp;&lt;/P&gt;&lt;P&gt;and if IDs (2102-205) are with TRCD =LDIAM only then select all IDs&amp;nbsp;&amp;nbsp;(2102-205) where&amp;nbsp;TRCD=LDIAM&lt;/P&gt;&lt;P&gt;and if IDs (2102-203) are with&amp;nbsp;TRCD=SAXIS then&amp;nbsp;then select all IDs (2102-203) where&amp;nbsp;TRCD=SAXIS&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From the following data;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TRLNKID&amp;nbsp; &amp;nbsp; &amp;nbsp; TRCD&amp;nbsp; &amp;nbsp; &amp;nbsp; ScanDate&lt;BR /&gt;2102-202&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;T01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;LDIAM&amp;nbsp; &amp;nbsp; &amp;nbsp; 11/1/2018&lt;BR /&gt;2102-208&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;T02&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SAXIS&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7/3/2018&lt;BR /&gt;2102-202&amp;nbsp; &amp;nbsp; &amp;nbsp; T02&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SAXIS&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5/4/2018&lt;BR /&gt;2102-202&amp;nbsp; &amp;nbsp; &amp;nbsp; T04&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;LDIAM&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5/4/2018&lt;BR /&gt;2102-203&amp;nbsp; &amp;nbsp; &amp;nbsp; T01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SAXIS&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5/25/2018&lt;BR /&gt;2102-203&amp;nbsp; &amp;nbsp; &amp;nbsp; T01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SAXIS&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8/14/2018&lt;BR /&gt;2102-203&amp;nbsp; &amp;nbsp; &amp;nbsp; T01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SAXIS&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5/5/2020&lt;BR /&gt;2102-203&amp;nbsp; &amp;nbsp; &amp;nbsp; T04&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SAXIS&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5/25/2018&lt;BR /&gt;2102-205&amp;nbsp; &amp;nbsp; &amp;nbsp; T01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; LDIAM&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6/14/2018&lt;BR /&gt;2102-205&amp;nbsp; &amp;nbsp; &amp;nbsp; T01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; LDIAM&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3/6/2020&lt;BR /&gt;2102-206&amp;nbsp; &amp;nbsp; &amp;nbsp; T02&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SAXIS&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 6/28/2018&lt;BR /&gt;2102-206&amp;nbsp; &amp;nbsp; &amp;nbsp; T03&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;LDIAM&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6/28/2018&lt;BR /&gt;2102-207&amp;nbsp; &amp;nbsp; &amp;nbsp; T02&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SAXIS&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6/25/2018&lt;BR /&gt;2102-207&amp;nbsp; &amp;nbsp; &amp;nbsp; T03&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SAXIS&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/15/2019&lt;BR /&gt;2102-208&amp;nbsp; &amp;nbsp; &amp;nbsp; T01&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; LDIAM&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;7/3/2018&lt;BR /&gt;2102-208&amp;nbsp; &amp;nbsp; &amp;nbsp; T02&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; SAXIS&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 7/3/2018&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It would be great help if anyone of you can help me. I'm new in this forum pls let me know if you need additional information.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2020 15:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-ID-with-multiple-conditions-either-or/m-p/667201#M199733</guid>
      <dc:creator>mahossain</dc:creator>
      <dc:date>2020-07-06T15:03:31Z</dc:date>
    </item>
    <item>
      <title>Re: List of ID with multiple conditions either or</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-ID-with-multiple-conditions-either-or/m-p/667225#M199749</link>
      <description>&lt;P&gt;I'm not sure I understand your objective. Are you just wanting the rows where one of those three conditions is satisfied? Or just the list of distinct IDs that satisfy one of those conditions?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This code will select the rows that satisfy one of those three conditions (as I understand them):&lt;/P&gt;
&lt;PRE&gt;data have;
    input ID $ TRLNKID $ TRCD $ ScanDate :mmddyy10.;
    format ScanDate mmddyy10.;
    datalines;
    2102-202 T01 LDIAM 11/1/2018
    2102-208 T02 SAXIS 7/3/2018
    2102-202 T02 SAXIS 5/4/2018
    2102-202 T04 LDIAM 5/4/2018
    2102-203 T01 SAXIS 5/25/2018
    2102-203 T01 SAXIS 8/14/2018
    2102-203 T01 SAXIS 5/5/2020
    2102-203 T04 SAXIS 5/25/2018
    2102-205 T01 LDIAM 6/14/2018
    2102-205 T01 LDIAM 3/6/2020
    2102-206 T02 SAXIS 6/28/2018
    2102-206 T03 LDIAM 6/28/2018
    2102-207 T02 SAXIS 6/25/2018
    2102-207 T03 SAXIS 1/15/2019
    2102-208 T01 LDIAM 7/3/2018
    2102-208 T02 SAXIS 7/3/2018
    ;
run;

data want;
    set have;
    where (ID = '2102-202' and TRCD = 'SAXIS')
       or (ID = '2102-205' and TRCD = 'LDIAM')
       or (ID = '2102-203' and TRCD = 'SAXIS');
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jul 2020 16:11:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-ID-with-multiple-conditions-either-or/m-p/667225#M199749</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-07-06T16:11:54Z</dc:date>
    </item>
    <item>
      <title>Re: List of ID with multiple conditions either or</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-ID-with-multiple-conditions-either-or/m-p/667232#M199754</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Yes, I want list of distinct IDs that satisfy the conditions. One ID my have in multiple rows which will fulfill the conditions. I gave here a small portion of data my whole data set.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2020 16:27:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-ID-with-multiple-conditions-either-or/m-p/667232#M199754</guid>
      <dc:creator>mahossain</dc:creator>
      <dc:date>2020-07-06T16:27:19Z</dc:date>
    </item>
    <item>
      <title>Re: List of ID with multiple conditions either or</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-ID-with-multiple-conditions-either-or/m-p/667233#M199755</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;Yes, I want list of distinct IDs that satisfy the conditions. One ID may have in multiple rows with either LDIAM or SAXIS.&lt;/P&gt;&lt;P&gt;I gave here a small portion of data my whole data set.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2020 16:30:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-ID-with-multiple-conditions-either-or/m-p/667233#M199755</guid>
      <dc:creator>mahossain</dc:creator>
      <dc:date>2020-07-06T16:30:40Z</dc:date>
    </item>
    <item>
      <title>Re: List of ID with multiple conditions either or</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-ID-with-multiple-conditions-either-or/m-p/667235#M199757</link>
      <description>Can you post what you expect the output to look like for this sample data?</description>
      <pubDate>Mon, 06 Jul 2020 16:34:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-ID-with-multiple-conditions-either-or/m-p/667235#M199757</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-07-06T16:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: List of ID with multiple conditions either or</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-ID-with-multiple-conditions-either-or/m-p/667239#M199759</link>
      <description>&lt;P&gt;Sure.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is my dataset;&lt;/P&gt;&lt;P&gt;ID TRLNKID TRCD ScanDate&lt;BR /&gt;2102-202 T01 LDIAM 11/1/2018&lt;BR /&gt;2102-202 T02 SAXIS 5/4/2018&lt;BR /&gt;2102-202 T04 LDIAM 5/4/2018&lt;BR /&gt;2102-203 T01 SAXIS 5/25/2018&lt;BR /&gt;2102-203 T01 SAXIS 8/14/2018&lt;BR /&gt;2102-203 T01 SAXIS 5/5/2020&lt;BR /&gt;2102-203 T04 SAXIS 5/25/2018&lt;BR /&gt;2102-205 T01 LDIAM 6/14/2018&lt;BR /&gt;2102-205 T01 LDIAM 3/6/2020&lt;BR /&gt;2102-206 T02 SAXIS 6/28/2018&lt;BR /&gt;2102-206 T03 LDIAM 6/28/2018&lt;BR /&gt;2102-207 T02 SAXIS 6/25/2018&lt;BR /&gt;2102-207 T03 SAXIS 1/15/2019&lt;BR /&gt;2102-208 T01 LDIAM 7/3/2018&lt;BR /&gt;2102-208 T02 SAXIS 7/3/2018&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what i'm expecting:&amp;nbsp;&lt;/P&gt;&lt;P&gt;ID TRLNKID TRCD ScanDate&lt;BR /&gt;2102-202 T02 SAXIS 5/4/2018&lt;BR /&gt;2102-203 T01 SAXIS 5/25/2018&lt;BR /&gt;2102-203 T01 SAXIS 8/14/2018&lt;BR /&gt;2102-203 T01 SAXIS 5/5/2020&lt;BR /&gt;2102-203 T04 SAXIS 5/25/2018&lt;BR /&gt;2102-205 T01 LDIAM 6/14/2018&lt;BR /&gt;2102-205 T01 LDIAM 3/6/2020&lt;BR /&gt;2102-206 T02 SAXIS 6/28/2018&lt;BR /&gt;2102-207 T02 SAXIS 6/25/2018&lt;BR /&gt;2102-207 T03 SAXIS 1/15/2019&lt;BR /&gt;2102-208 T02 SAXIS 7/3/2018&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: If an ID have values 'SAXIS' and 'LDIAM' i will select all those IDs with 'SAXIS'; if ID have is only 'LDIAM' then i i'll select all those IDs with&amp;nbsp;'LDIAM' and if the ID have values only 'SAXIS' i'll select all those IDs with 'SAXIS'.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jul 2020 16:53:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-ID-with-multiple-conditions-either-or/m-p/667239#M199759</guid>
      <dc:creator>mahossain</dc:creator>
      <dc:date>2020-07-06T16:53:50Z</dc:date>
    </item>
    <item>
      <title>Re: List of ID with multiple conditions either or</title>
      <link>https://communities.sas.com/t5/SAS-Programming/List-of-ID-with-multiple-conditions-either-or/m-p/667283#M199775</link>
      <description>&lt;P&gt;This should work, for the sample data you provided (i.e. having only those two TRCDs).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As I understood it, this is your logic for each distinct ID:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;1. If any of the records for that ID have TRCD = 'SAXIS', then output only those records where TRCD = 'SAXIS'&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;2. Otherwise, if any of the records for that ID have TRCD = 'LDIAM', then output only those records where TRCD = 'LDIAM'&lt;/P&gt;
&lt;P&gt;Does that seem correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sort data=have out=have_sorted; by ID descending TRCD; run;

data want;
    set have_sorted;
    by ID;
    retain only_saxis;
    if first.ID then do;
        if TRCD = 'SAXIS' then only_saxis = 1;
        else only_saxis = 0;
    end;
    if only_saxis = 1 and TRCD = 'SAXIS' then output;
    else if only_saxis = 0 and TRCD = 'LDIAM' then output;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 06 Jul 2020 19:46:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/List-of-ID-with-multiple-conditions-either-or/m-p/667283#M199775</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-07-06T19:46:45Z</dc:date>
    </item>
  </channel>
</rss>

