<?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: Exclude certain id's based on the criteria in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Exclude-certain-id-s-based-on-the-criteria/m-p/711894#M219365</link>
    <description>Thank you novinosrin. You solved this complicated query in such a simple step. I spent at least 2 -3 hours with several steps. I tested this on one day's worth of data and looks perfect. Need to see if any of the data is falling into cracks as I get the note: NOTE: The query requires remerging summary statistics back with the original data.&lt;BR /&gt;&lt;BR /&gt;I always use distinct function on one field to get the line list, but you have used distinct function on different fields and made this so simple. May be I need to update my SQL skills. Once again thank you so much.</description>
    <pubDate>Sat, 16 Jan 2021 22:42:03 GMT</pubDate>
    <dc:creator>Stalk</dc:creator>
    <dc:date>2021-01-16T22:42:03Z</dc:date>
    <item>
      <title>Exclude certain id's based on the criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exclude-certain-id-s-based-on-the-criteria/m-p/711805#M219325</link>
      <description>&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;How can I exclude only 1, 5 and 7 records..&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; temp_copy;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;infile&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; cards &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;dlm&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'|'&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;truncover&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; subDate :&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;mmddyy10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; TestID :&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;$5.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; LogDept :&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;$2.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; CurrentDept :&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;$2.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; status :&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;$8.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; Category &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;$4.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; subDate &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#008080"&gt;yymmdd10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;cards&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;10/21/2020|29545|54|99|Active|K12&lt;/P&gt;&lt;P&gt;10/21/2020|29545|54|99|Active|K6&lt;/P&gt;&lt;P&gt;10/21/2020|29545|54|99|Active|K9&lt;/P&gt;&lt;P&gt;10/30/2020|56545|45|99|Active|K12&lt;/P&gt;&lt;P&gt;10/30/2020|56545|45|99|InActive|K12&lt;/P&gt;&lt;P&gt;10/30/2020|56545|45|88|Active|K12&lt;/P&gt;&lt;P&gt;11/21/2020|49545|33|99|Active|K12&lt;/P&gt;&lt;P&gt;11/21/2020|49545|33|99|Active|K9&lt;/P&gt;&lt;P&gt;11/21/2020|99546|56|94|shipped|K6&lt;/P&gt;&lt;P&gt;11/21/2020|99546|56|94|shipped|K9&lt;/P&gt;&lt;P&gt;11/21/2020|99546|56|99|shipped|K9&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;create&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; test &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;as&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;select&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;distinct&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; testid, subDate, CurrentDept, Status, category&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; temp_copy &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;order&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; testid, subDate, CurrentDept, Status, category&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; lastcategory;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; test;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;by&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; testid subDate CurrentDept Status category;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; last.CurrentDept;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; CurrentDept= &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'99'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; and Status=&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;"InActive"&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;then&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;delete&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;/*conditions to check..&lt;/P&gt;&lt;P&gt;If TestId is in 2 or more categories then count only in K6 &amp;amp; K9, because K12 is the parent and should be excluded; but if TestId is&amp;nbsp;in only K12 category and in 2 different currentDept then keep both the records.&lt;/P&gt;&lt;P&gt;If CurrentDept='99' and status='InActive' then delete;*/&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jan 2021 23:24:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exclude-certain-id-s-based-on-the-criteria/m-p/711805#M219325</guid>
      <dc:creator>Stalk</dc:creator>
      <dc:date>2021-01-15T23:24:02Z</dc:date>
    </item>
    <item>
      <title>Re: Exclude certain id's based on the criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exclude-certain-id-s-based-on-the-criteria/m-p/711813#M219329</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/358432"&gt;@Stalk&lt;/a&gt;&amp;nbsp; Assuming I kinda understand&amp;nbsp;what you&amp;nbsp;want--&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp_copy;

infile cards dlm='|' truncover ;

input subDate :mmddyy10. TestID :$5. LogDept :$2. CurrentDept :$2. status :$8. Category $4.;

format subDate yymmdd10.;

cards;
10/21/2020|29545|54|99|Active|K12
10/21/2020|29545|54|99|Active|K6
10/21/2020|29545|54|99|Active|K9
10/30/2020|56545|45|99|Active|K12
10/30/2020|56545|45|99|InActive|K12
10/30/2020|56545|45|88|Active|K12
11/21/2020|49545|33|99|Active|K12
11/21/2020|49545|33|99|Active|K9
11/21/2020|99546|56|94|shipped|K6
11/21/2020|99546|56|94|shipped|K9
11/21/2020|99546|56|99|shipped|K9
;

proc sql;
 create table want(drop=_c:) as
 select * ,count(distinct Category) as _c,count(distinct currentdept) as _c1
 from temp_copy
 where not(CurrentDept= '99' and Status="InActive")
 group by testid
 having _c&amp;gt;=2 and Category ne 'K12' or  _c=1 and Category='K12' and _c1&amp;gt;=2;
quit;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 16 Jan 2021 00:33:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exclude-certain-id-s-based-on-the-criteria/m-p/711813#M219329</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-01-16T00:33:24Z</dc:date>
    </item>
    <item>
      <title>Re: Exclude certain id's based on the criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exclude-certain-id-s-based-on-the-criteria/m-p/711894#M219365</link>
      <description>Thank you novinosrin. You solved this complicated query in such a simple step. I spent at least 2 -3 hours with several steps. I tested this on one day's worth of data and looks perfect. Need to see if any of the data is falling into cracks as I get the note: NOTE: The query requires remerging summary statistics back with the original data.&lt;BR /&gt;&lt;BR /&gt;I always use distinct function on one field to get the line list, but you have used distinct function on different fields and made this so simple. May be I need to update my SQL skills. Once again thank you so much.</description>
      <pubDate>Sat, 16 Jan 2021 22:42:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exclude-certain-id-s-based-on-the-criteria/m-p/711894#M219365</guid>
      <dc:creator>Stalk</dc:creator>
      <dc:date>2021-01-16T22:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: Exclude certain id's based on the criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exclude-certain-id-s-based-on-the-criteria/m-p/711895#M219366</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/358432"&gt;@Stalk&lt;/a&gt;&amp;nbsp;Don't worry about &lt;STRONG&gt;"NOTE: The query requires remerging summary statistics back with the original data."&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I needed the SQL processor to actually take advantage of automatic merge back with the original in order to have an &lt;EM&gt;&lt;STRONG&gt;extra pass&lt;/STRONG&gt;&lt;/EM&gt; of the BY GROUP for the filter to subset the needed records. So that was on purpose.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Jan 2021 22:49:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exclude-certain-id-s-based-on-the-criteria/m-p/711895#M219366</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-01-16T22:49:04Z</dc:date>
    </item>
    <item>
      <title>Re: Exclude certain id's based on the criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exclude-certain-id-s-based-on-the-criteria/m-p/711897#M219367</link>
      <description>Actually I NEED to keep/count the TestID for K12 category if they don't exist in any other categories. Currently if the count=1 for K12 they are all excluded.</description>
      <pubDate>Sat, 16 Jan 2021 23:17:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exclude-certain-id-s-based-on-the-criteria/m-p/711897#M219367</guid>
      <dc:creator>Stalk</dc:creator>
      <dc:date>2021-01-16T23:17:43Z</dc:date>
    </item>
    <item>
      <title>Re: Exclude certain id's based on the criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exclude-certain-id-s-based-on-the-criteria/m-p/711899#M219368</link>
      <description>&lt;P&gt;Not sure, what you mean. You could perhaps post a clear sample of your HAVE and WANT explaining the logic in points.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Jan 2021 23:41:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exclude-certain-id-s-based-on-the-criteria/m-p/711899#M219368</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-01-16T23:41:27Z</dc:date>
    </item>
    <item>
      <title>Re: Exclude certain id's based on the criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exclude-certain-id-s-based-on-the-criteria/m-p/711902#M219369</link>
      <description>I added 2 more cards where only one TestID exists for Category=K12 and I want to keep the below two records in addition to the above list.. ..Total my want table should have 10 records&lt;BR /&gt;&lt;BR /&gt;11/25/2020|98548|75|99|shipped|K12&lt;BR /&gt;11/26/2020|98549|76|88|shipped|K12</description>
      <pubDate>Sun, 17 Jan 2021 00:59:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exclude-certain-id-s-based-on-the-criteria/m-p/711902#M219369</guid>
      <dc:creator>Stalk</dc:creator>
      <dc:date>2021-01-17T00:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: Exclude certain id's based on the criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exclude-certain-id-s-based-on-the-criteria/m-p/711908#M219370</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/358432"&gt;@Stalk&lt;/a&gt;&amp;nbsp; &amp;nbsp;Do you mean this change?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; having _c&amp;gt;=2 and Category ne 'K12' or  _c=1 and Category='K12';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;full code-&amp;gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
 create table want(drop=_c:) as
 select * ,count(distinct Category) as _c
 from temp_copy
 where not(CurrentDept= '99' and Status="InActive")
 group by testid
 having _c&amp;gt;=2 and Category ne 'K12' or  _c=1 and Category='K12';
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 17 Jan 2021 01:29:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exclude-certain-id-s-based-on-the-criteria/m-p/711908#M219370</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2021-01-17T01:29:49Z</dc:date>
    </item>
    <item>
      <title>Re: Exclude certain id's based on the criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exclude-certain-id-s-based-on-the-criteria/m-p/711910#M219371</link>
      <description>yes, it worked. Thank you for your time and solution.</description>
      <pubDate>Sun, 17 Jan 2021 01:59:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exclude-certain-id-s-based-on-the-criteria/m-p/711910#M219371</guid>
      <dc:creator>Stalk</dc:creator>
      <dc:date>2021-01-17T01:59:37Z</dc:date>
    </item>
  </channel>
</rss>

