<?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: How to select observations if they ever have a specified value in different a variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-observations-if-they-ever-have-a-specified-value/m-p/899482#M355532</link>
    <description>&lt;P&gt;This is a data step solution, using a hash object containing the only id's that have any instance of 'YES':&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Untested, in the absence of sample data in the form of a working data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have;
  if _n_=1 then do;
    declare hash ids_with_yes (dataset:'have (keep=id pending where=(pending="YES"))');
      ids_with_yes.definekey('id');
      ids_with_yes.definedata('id');
      ids_with_yes.definedone();
  end;
  if ids_with_yes.check()=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 23 Oct 2023 22:10:21 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2023-10-23T22:10:21Z</dc:date>
    <item>
      <title>How to select observations if they ever have a specified value in different a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-observations-if-they-ever-have-a-specified-value/m-p/899450#M355517</link>
      <description>&lt;P&gt;Hello ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How could I select Observations (Rows) where if their Pending column ever says "YES" then output to a new dataset? I am thinking to use proc sql but also, I'm still learning as I go so I feel stuck. Below is my have data and want data tables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt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lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Test_Date&lt;/TD&gt;&lt;TD&gt;Pending&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;TA&lt;/TD&gt;&lt;TD&gt;3/29/22&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;TA&lt;/TD&gt;&lt;TD&gt;3/29/22&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;TA&lt;/TD&gt;&lt;TD&gt;3/29/22&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;LT&lt;/TD&gt;&lt;TD&gt;4/5/22&lt;/TD&gt;&lt;TD&gt;YES&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;LT&lt;/TD&gt;&lt;TD&gt;4/5/22&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;LT&lt;/TD&gt;&lt;TD&gt;4/5/22&lt;/TD&gt;&lt;TD&gt;NO&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 20 Oct 2023 19:27:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-observations-if-they-ever-have-a-specified-value/m-p/899450#M355517</guid>
      <dc:creator>rebelde52</dc:creator>
      <dc:date>2023-10-20T19:27:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to select observations if they ever have a specified value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-observations-if-they-ever-have-a-specified-value/m-p/899453#M355518</link>
      <description>&lt;P&gt;From now on, please provide data as working SAS data step code (&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;examples and instructions&lt;/A&gt;) and not as Excel copy and paste. Also, you would make your own typing/coding simpler if YES/NO character strings were actually 0/1 numeric values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	create table want as select *
	from have  	
	group by id
	having sum(pending='YES')&amp;gt;=1;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Oct 2023 19:31:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-observations-if-they-ever-have-a-specified-value/m-p/899453#M355518</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-10-20T19:31:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to select observations if they ever have a specified value in different a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-observations-if-they-ever-have-a-specified-value/m-p/899482#M355532</link>
      <description>&lt;P&gt;This is a data step solution, using a hash object containing the only id's that have any instance of 'YES':&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Untested, in the absence of sample data in the form of a working data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want ;
  set have;
  if _n_=1 then do;
    declare hash ids_with_yes (dataset:'have (keep=id pending where=(pending="YES"))');
      ids_with_yes.definekey('id');
      ids_with_yes.definedata('id');
      ids_with_yes.definedone();
  end;
  if ids_with_yes.check()=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Oct 2023 22:10:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-observations-if-they-ever-have-a-specified-value/m-p/899482#M355532</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-10-23T22:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to select observations if they ever have a specified value in different a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-observations-if-they-ever-have-a-specified-value/m-p/900278#M355805</link>
      <description>&lt;P&gt;data new;&lt;/P&gt;&lt;P&gt;set ...;&lt;/P&gt;&lt;P&gt;where ID= "PG";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc print data = new;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2023 09:26:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-observations-if-they-ever-have-a-specified-value/m-p/900278#M355805</guid>
      <dc:creator>Kondala</dc:creator>
      <dc:date>2023-10-27T09:26:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to select observations if they ever have a specified value in different a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-observations-if-they-ever-have-a-specified-value/m-p/900281#M355807</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/441125"&gt;@rebelde52&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;already gave you great solutions, so I'm adding this on just for fun.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID $	Test_Date :mmddyy8.	Pending $;
format Test_Date mmddyy10.;
cards;
TA 3/29/22 NO
TA 3/29/22 NO
TA 3/29/22 YES
PG 3/29/22 NO
PG 4/5/22 NO
LT 4/5/22 YES
LT 4/5/22 NO
LT 4/5/22 NO
;
run;
proc print;
run;

data want;
  _N_=0;
  do until(last.ID);
    set have;
    by ID notsorted;
    _N_ + Pending="YES";  
  end;

  do until(last.ID);
    set have;
    by ID notsorted;
    if _N_ then output; 
  end;
run;
proc print;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;{EDIT:}&lt;/P&gt;
&lt;P&gt;One more for "lazy typers":&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro DoW(code);
  do until(last.ID);
    set have;
    by ID notsorted;
    &amp;amp;code.;  
  end;
%mend;

data want;
  _N_=0;
  %DoW(_N_ + Pending="YES")  
  %DoW(if _N_ then output) 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Oct 2023 09:46:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-observations-if-they-ever-have-a-specified-value/m-p/900281#M355807</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-10-27T09:46:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to select observations if they ever have a specified value in different a variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-select-observations-if-they-ever-have-a-specified-value/m-p/900283#M355809</link>
      <description>&lt;P&gt;I did a test, works perfect (as usual).&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Fri, 27 Oct 2023 09:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-select-observations-if-they-ever-have-a-specified-value/m-p/900283#M355809</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2023-10-27T09:41:14Z</dc:date>
    </item>
  </channel>
</rss>

