<?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 derive only n flag records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-derive-only-n-flag-records/m-p/568846#M160217</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;: Oh, ok. I definitely did not understand that was the ask from the original post. Thanks for clearing that up.&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/209685"&gt;@thanikondharish&lt;/a&gt;&amp;nbsp;: Now that I understand what you are looking for, here is a third option to accomplish the output you need:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE WORK.WANT	AS
	SELECT DISTINCT
		  ID
		, Name

	FROM WORK.HAVE
	GROUP BY ID, Name
	HAVING SUM(CASE WHEN Flag='y' then 1 else 0 end)=0;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Results:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;id	name
103	dhanush
104	sai&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 25 Jun 2019 16:00:47 GMT</pubDate>
    <dc:creator>tsap</dc:creator>
    <dc:date>2019-06-25T16:00:47Z</dc:date>
    <item>
      <title>how to derive only n flag records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-derive-only-n-flag-records/m-p/568109#M159862</link>
      <description>&lt;P&gt;data ex ;&lt;BR /&gt;input id $ name $ flag $ ;&lt;BR /&gt;cards ;&lt;BR /&gt;101 surya y&lt;BR /&gt;101 surya y&lt;BR /&gt;101 surya n&lt;BR /&gt;102 bulli y&lt;BR /&gt;103 dhanush n&lt;BR /&gt;103 dhanush n&lt;BR /&gt;104 sai n&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i have one data set like above . How to derive n flag for example&lt;/P&gt;&lt;P&gt;id should have only n value shouldn't be other values like see below example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1)103 dhanush n&lt;/P&gt;&lt;P&gt;2)104 sai n&lt;/P&gt;&lt;P&gt;103,104 have only n value&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jun 2019 06:32:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-derive-only-n-flag-records/m-p/568109#M159862</guid>
      <dc:creator>thanikondharish</dc:creator>
      <dc:date>2019-06-22T06:32:02Z</dc:date>
    </item>
    <item>
      <title>Re: how to derive only n flag records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-derive-only-n-flag-records/m-p/568110#M159863</link>
      <description>&lt;P&gt;Here is one way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   if _N_ = 1 then do;
      declare hash h(dataset:"ex(where=(flag='y'))");
      h.defineKey('id');
      h.defineDone();
   end;

   set ex;
   if h.check() ne 0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Jun 2019 06:43:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-derive-only-n-flag-records/m-p/568110#M159863</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-06-22T06:43:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to derive only n flag records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-derive-only-n-flag-records/m-p/568150#M159881</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/209685"&gt;@thanikondharish&lt;/a&gt;:&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/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;'s solution is best since it doesn't depend on the record order and will work whether the input data set is unsorted or sorted.&amp;nbsp;If it is sorted, though (as in your sample), the double DoW-loop is the usual vehicle to get where you need:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ex ;                             
input id $ name $ flag $ ;            
cards ;                               
101 surya   y                         
101 surya   y                         
101 surya   n                         
102 bulli   y                         
103 dhanush n                         
103 dhanush n                         
104 sai     n                         
run ;                                 
                                      
data need (drop = _:) ;               
  do _n_ = 1 by 1 until (last.id) ;   
    set ex ;                          
    by id ;                           
    if flag = "y" then _exclude = 1 ; 
  end ;                               
  do _n_ = 1 to _n_ ;    &lt;BR /&gt;    set ex ;               
    if not _exclude then output ;     
  end ;                               
run ;                                 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jun 2019 18:49:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-derive-only-n-flag-records/m-p/568150#M159881</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-06-22T18:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: how to derive only n flag records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-derive-only-n-flag-records/m-p/568722#M160157</link>
      <description>&lt;P&gt;If the only expectation for output, is that all values in the flag field are set to 'n', then the logic could be as simple as this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.WANT;
	SET WORK.HAVE;
	Flag='n';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Or if you would prefer not to overwrite the flag field you can use this logic:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.WANT (RENAME=(Flag2=Flag));
	SET WORK.HAVE;
	FLAG2='n';
	DROP FLAG;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to use conditional logic to review the current values of flag and update only the ones containing 'y' to 'n', then you can definitely go with the alternative solutions provided by the other users.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 12:30:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-derive-only-n-flag-records/m-p/568722#M160157</guid>
      <dc:creator>tsap</dc:creator>
      <dc:date>2019-06-25T12:30:44Z</dc:date>
    </item>
    <item>
      <title>Re: how to derive only n flag records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-derive-only-n-flag-records/m-p/568843#M160215</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22122"&gt;@tsap&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;If it were &lt;EM&gt;the&lt;/EM&gt; expectation, you'd be right. But it's not: The expectation is to output each group of records with the same ID where all the values of flag="n"; or, in other words, exclude any ID-group where at least one record has flag not equal to "n".&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 15:51:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-derive-only-n-flag-records/m-p/568843#M160215</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-06-25T15:51:18Z</dc:date>
    </item>
    <item>
      <title>Re: how to derive only n flag records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-derive-only-n-flag-records/m-p/568846#M160217</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;: Oh, ok. I definitely did not understand that was the ask from the original post. Thanks for clearing that up.&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/209685"&gt;@thanikondharish&lt;/a&gt;&amp;nbsp;: Now that I understand what you are looking for, here is a third option to accomplish the output you need:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE WORK.WANT	AS
	SELECT DISTINCT
		  ID
		, Name

	FROM WORK.HAVE
	GROUP BY ID, Name
	HAVING SUM(CASE WHEN Flag='y' then 1 else 0 end)=0;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Results:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;id	name
103	dhanush
104	sai&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 16:00:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-derive-only-n-flag-records/m-p/568846#M160217</guid>
      <dc:creator>tsap</dc:creator>
      <dc:date>2019-06-25T16:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to derive only n flag records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-derive-only-n-flag-records/m-p/568847#M160218</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/22122"&gt;@tsap&lt;/a&gt;&amp;nbsp;: Yup, that is it.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 16:03:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-derive-only-n-flag-records/m-p/568847#M160218</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-06-25T16:03:31Z</dc:date>
    </item>
  </channel>
</rss>

