<?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: identify unique observation per subject based on multiple conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/identify-unique-observation-per-subject-based-on-multiple/m-p/291613#M270075</link>
    <description>&lt;P&gt;You can add in a custom sort variable, sort the variable and then take the first/last depending on your logic. Here's a way using proc format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input id value;
	value_order=put(value, order_fmt. -l);
	cards;
1 0
1 1
1 2
2 0
2 0
2 2
2 0
3 0
3 0
3 0
3 0
;

proc format ;
	value order_fmt 1=1 2=2 0=3;
run;

proc sort data=have;
	by id value_order;
run;

data want;
	set have;
	by id;

	if first.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 14 Aug 2016 21:39:07 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-08-14T21:39:07Z</dc:date>
    <item>
      <title>identify unique observation per subject based on multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/identify-unique-observation-per-subject-based-on-multiple/m-p/291609#M270074</link>
      <description>&lt;P&gt;Have:&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;value&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&g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t;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to select one observation per subject. if the value is 1 then retain that observation. if not 1 then look for value 2 and retain it. if both 1 and 2 &amp;nbsp;are not there then look for 0 and retian it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate any help to get the output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;</description>
      <pubDate>Sun, 14 Aug 2016 21:17:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/identify-unique-observation-per-subject-based-on-multiple/m-p/291609#M270074</guid>
      <dc:creator>ari</dc:creator>
      <dc:date>2016-08-14T21:17:15Z</dc:date>
    </item>
    <item>
      <title>Re: identify unique observation per subject based on multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/identify-unique-observation-per-subject-based-on-multiple/m-p/291613#M270075</link>
      <description>&lt;P&gt;You can add in a custom sort variable, sort the variable and then take the first/last depending on your logic. Here's a way using proc format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input id value;
	value_order=put(value, order_fmt. -l);
	cards;
1 0
1 1
1 2
2 0
2 0
2 2
2 0
3 0
3 0
3 0
3 0
;

proc format ;
	value order_fmt 1=1 2=2 0=3;
run;

proc sort data=have;
	by id value_order;
run;

data want;
	set have;
	by id;

	if first.id;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 14 Aug 2016 21:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/identify-unique-observation-per-subject-based-on-multiple/m-p/291613#M270075</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-14T21:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: identify unique observation per subject based on multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/identify-unique-observation-per-subject-based-on-multiple/m-p/291658#M270076</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select  distinct A.ID,
          case  when exists(select distinct ID from HAVE where ID=A.ID and VALUE=1) then 1
                when exists(select distinct ID from HAVE where ID=A.ID and VALUE=2) then 2
                else 0 end as VALUE
  from    HAVE A;
quit;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Aug 2016 09:15:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/identify-unique-observation-per-subject-based-on-multiple/m-p/291658#M270076</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-08-15T09:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: identify unique observation per subject based on multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/identify-unique-observation-per-subject-based-on-multiple/m-p/291686#M270077</link>
      <description>&lt;P&gt;Thanks Reeza&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2016 14:03:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/identify-unique-observation-per-subject-based-on-multiple/m-p/291686#M270077</guid>
      <dc:creator>ari</dc:creator>
      <dc:date>2016-08-15T14:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: identify unique observation per subject based on multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/identify-unique-observation-per-subject-based-on-multiple/m-p/291687#M270078</link>
      <description>&lt;P&gt;Thanks RW9&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2016 14:04:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/identify-unique-observation-per-subject-based-on-multiple/m-p/291687#M270078</guid>
      <dc:creator>ari</dc:creator>
      <dc:date>2016-08-15T14:04:19Z</dc:date>
    </item>
  </channel>
</rss>

