<?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: I have a dataset which has flags and want to nodupkey them but have a problem in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/I-have-a-dataset-which-has-flags-and-want-to-nodupkey-them-but/m-p/309670#M66718</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by sub flag;
run;

data want;
set have;
by sub;
if last.sub;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since 'Y' comes after 'N' in the sort order, this gets what you want.&lt;/P&gt;
&lt;P&gt;If you want the last visit where flag was 'Y', add visit to the by statement in the sort.&lt;/P&gt;</description>
    <pubDate>Mon, 07 Nov 2016 09:29:08 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-11-07T09:29:08Z</dc:date>
    <item>
      <title>I have a dataset which has flags and want to nodupkey them but have a problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-have-a-dataset-which-has-flags-and-want-to-nodupkey-them-but/m-p/309662#M66712</link>
      <description>&lt;P&gt;I created a flag variable like the below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data da1;&lt;BR /&gt; set da;&lt;BR /&gt; where visitnum gt 3;&lt;BR /&gt; if dastresn gt 0 then do; FLAG="Y"; &lt;SPAN&gt;FLAGN&lt;/SPAN&gt;=1; end;&lt;BR /&gt; if dastresn le 0 then do; &lt;SPAN&gt;FLAG&lt;/SPAN&gt;="N"; &lt;SPAN&gt;FLAGN&lt;/SPAN&gt;=0; end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now for some subjs i get both Y and N and in those cases i only need Y.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used nodupkey to get unique subjects but in some subjects i get flag as N&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2016 08:54:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-have-a-dataset-which-has-flags-and-want-to-nodupkey-them-but/m-p/309662#M66712</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2016-11-07T08:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: I have a dataset which has flags and want to nodupkey them but have a problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-have-a-dataset-which-has-flags-and-want-to-nodupkey-them-but/m-p/309663#M66713</link>
      <description>&lt;P&gt;Can you provide some sample data for your problem? &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2016 08:57:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-have-a-dataset-which-has-flags-and-want-to-nodupkey-them-but/m-p/309663#M66713</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2016-11-07T08:57:26Z</dc:date>
    </item>
    <item>
      <title>Re: I have a dataset which has flags and want to nodupkey them but have a problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-have-a-dataset-which-has-flags-and-want-to-nodupkey-them-but/m-p/309664#M66714</link>
      <description>&lt;P&gt;sub visit flag&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp; Y&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; 4 &amp;nbsp; &amp;nbsp; Y&lt;/P&gt;
&lt;P&gt;2 &amp;nbsp; &amp;nbsp; 4 &amp;nbsp; &amp;nbsp; N&lt;/P&gt;
&lt;P&gt;2 &amp;nbsp; &amp;nbsp; 5 &amp;nbsp; &amp;nbsp; N&lt;/P&gt;
&lt;P&gt;2 &amp;nbsp; &amp;nbsp; 6 &amp;nbsp; &amp;nbsp;Y&lt;/P&gt;
&lt;P&gt;3 &amp;nbsp; &amp;nbsp; 4 &amp;nbsp; &amp;nbsp;Y&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the above if i want unique sub i do nodupkey on sub but for sub 2 the flag is N and Y and i only get N as it is first. FOr sub 2 i want Y if it has both N and Y&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2016 09:03:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-have-a-dataset-which-has-flags-and-want-to-nodupkey-them-but/m-p/309664#M66714</guid>
      <dc:creator>vraj1</dc:creator>
      <dc:date>2016-11-07T09:03:09Z</dc:date>
    </item>
    <item>
      <title>Re: I have a dataset which has flags and want to nodupkey them but have a problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-have-a-dataset-which-has-flags-and-want-to-nodupkey-them-but/m-p/309666#M66716</link>
      <description>&lt;P&gt;Thats not a nodupkey then, nodupkey removes duplicate information based on the by grouping. &amp;nbsp;Yours is a logical problem. &amp;nbsp;I would say (and as there is no test data in the form of a datastep this is just theory):&lt;/P&gt;
&lt;P&gt;sort your data with your flag in descending order on flag&lt;/P&gt;
&lt;P&gt;do a datastep by subjid, if last.subjid then output&lt;/P&gt;
&lt;P&gt;This way if Y exists it will be first.subjid due to the sort, otherwise N will be there.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2016 09:14:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-have-a-dataset-which-has-flags-and-want-to-nodupkey-them-but/m-p/309666#M66716</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-07T09:14:36Z</dc:date>
    </item>
    <item>
      <title>Re: I have a dataset which has flags and want to nodupkey them but have a problem</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-have-a-dataset-which-has-flags-and-want-to-nodupkey-them-but/m-p/309670#M66718</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by sub flag;
run;

data want;
set have;
by sub;
if last.sub;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since 'Y' comes after 'N' in the sort order, this gets what you want.&lt;/P&gt;
&lt;P&gt;If you want the last visit where flag was 'Y', add visit to the by statement in the sort.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Nov 2016 09:29:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-have-a-dataset-which-has-flags-and-want-to-nodupkey-them-but/m-p/309670#M66718</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-07T09:29:08Z</dc:date>
    </item>
  </channel>
</rss>

