<?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: Conditional Selection in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15132#M2602</link>
    <description>Sorry Paige, if I was not explanatory enough, here we go:&lt;BR /&gt;
&lt;BR /&gt;
In the table below, Observation 1 and Observation 5 have the same SA value, but the DA value of Observation 1 is greater than that of Observation 5 so in reading the data, Observation 1 will be selected but Observation 5 will be dropped.&lt;BR /&gt;
&lt;BR /&gt;
Again Observation 2 and Observation 13 have the same SA values, and incidentally their AD values are also the same, so here we resort to their RS values (which are not the same). The RS value of Observation 13 is higher, so it will be selected and Observation 2 dropped.&lt;BR /&gt;
&lt;BR /&gt;
Observations with unique SA values will be selected.&lt;BR /&gt;
&lt;BR /&gt;
Observations 4, 7, 8, 12 will not be selected because they have the values Tl,  Ng, Yd and Tl respectively.&lt;BR /&gt;
&lt;BR /&gt;
Observation	SA	AD	RS	SP&lt;BR /&gt;
1	                15	20	19	Bt&lt;BR /&gt;
2	                18	21	22	Ab&lt;BR /&gt;
3	                16	18	16	Ab&lt;BR /&gt;
4	                10	12	15	Tl&lt;BR /&gt;
5	                15	19	17	Bt&lt;BR /&gt;
6	                20	22	24	Ef&lt;BR /&gt;
7	               13	16	17	Ng&lt;BR /&gt;
8	               26	27	29	Yd&lt;BR /&gt;
9	               22	23	26	Ef&lt;BR /&gt;
10	               24	26	28	Dd&lt;BR /&gt;
11	               23	25	27	Bt&lt;BR /&gt;
12	               27	29	30	Tl&lt;BR /&gt;
13	               18	21	23	Ef&lt;BR /&gt;
14	               21	22	25	Ab&lt;BR /&gt;
15	              12	14	16	Dd</description>
    <pubDate>Tue, 12 Oct 2010 14:59:57 GMT</pubDate>
    <dc:creator>EMKBB</dc:creator>
    <dc:date>2010-10-12T14:59:57Z</dc:date>
    <item>
      <title>Conditional Selection</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15122#M2592</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
I am new to SAS, and I am looking for material that will enable me to code and do the following:&lt;BR /&gt;
&lt;BR /&gt;
I am trying to select the observations in a data set that meet the following criteria:&lt;BR /&gt;
&lt;BR /&gt;
Variables: SA, AD, RS, SP (there are other variables but these are what is needed                  &lt;BR /&gt;
                                         to do the selection).&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
When  SA(i)  equals  SA(j)  and  AD(i)  is not equal to  AD(j)&lt;BR /&gt;
Select  Observation  i   if  AD(i)  is  greater  than  AD(j)&lt;BR /&gt;
Select  Observation  j   if  AD(i)  is  less  than  AD(j),&lt;BR /&gt;
&lt;BR /&gt;
When  SA(i) equals  SA(j)  and  AD(i)  equals  AD(j)&lt;BR /&gt;
Select  Observation  i   if  RS(i)  is  greater than  RS(j)&lt;BR /&gt;
Select  Observation  j   if  RS(i)  is  less  than  RS(j),&lt;BR /&gt;
&lt;BR /&gt;
Ignore  Observation  i   if  SP(i)  equal  to  Yd or Tl or Ng.&lt;BR /&gt;
&lt;BR /&gt;
 &lt;BR /&gt;
Thank you.</description>
      <pubDate>Mon, 11 Oct 2010 15:17:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15122#M2592</guid>
      <dc:creator>EMKBB</dc:creator>
      <dc:date>2010-10-11T15:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Selection</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15123#M2593</link>
      <description>&amp;gt; I am trying to select the observations in a data set&lt;BR /&gt;
&amp;gt; that meet the following criteria:&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; Variables: SA, AD, RS, SP (there are other variables&lt;BR /&gt;
&amp;gt; but these are what is needed                  &lt;BR /&gt;
&amp;gt; to do the selection).&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; When  SA(i)  equals  SA(j)  and  AD(i)  is not equal&lt;BR /&gt;
&amp;gt; to  AD(j)&lt;BR /&gt;
&lt;BR /&gt;
Not sure what this means ... normally, you don't select an observation based upon the value of the same variable in another observation. Do you mean select observation (i) when the value of SA equals the value of SA in some other observation (j), along with AD conditions?&lt;BR /&gt;
&lt;BR /&gt;
If you really want to select an observation based upon a general condition where SA equals the value of SA in some other observation (plus AD conditions), where the other observation could be anywhere in the data set, I think you'd need PROC IML.&lt;BR /&gt;
&lt;BR /&gt;
Am I understanding you properly?

Message was edited by: Paige</description>
      <pubDate>Mon, 11 Oct 2010 15:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15123#M2593</guid>
      <dc:creator>Paige</dc:creator>
      <dc:date>2010-10-11T15:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Selection</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15124#M2594</link>
      <description>Thanks Paige,&lt;BR /&gt;
&lt;BR /&gt;
What I mean is that if two observations have the same SA value, then select the one with the higher AD value. If it turns out that their AD values are also the same, then select the one with the higher RS value. &lt;BR /&gt;
&lt;BR /&gt;
Any observation whose SP value is equal  to  Yd or Tl or Ng should not be selected.&lt;BR /&gt;
&lt;BR /&gt;
All observations which have unique SA values will be selected.&lt;BR /&gt;
&lt;BR /&gt;
(I used i and j to identify any two given observations. I hope the situation is clearer now).&lt;BR /&gt;
&lt;BR /&gt;
EMKBB</description>
      <pubDate>Mon, 11 Oct 2010 17:58:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15124#M2594</guid>
      <dc:creator>EMKBB</dc:creator>
      <dc:date>2010-10-11T17:58:55Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Selection</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15125#M2595</link>
      <description>I still don't think I know enough to actually a the program to do this. Are you comparing all observations to each other? Or selected pairs (triples/quads/etc.) only? If so, how are you selecting the pairs?&lt;BR /&gt;
&lt;BR /&gt;
But as a guess, does this meet your needs? Sort by SA AD RS. Now things are ordered such that choosing the one you want should be easy.</description>
      <pubDate>Mon, 11 Oct 2010 18:21:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15125#M2595</guid>
      <dc:creator>Paige</dc:creator>
      <dc:date>2010-10-11T18:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Selection</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15126#M2596</link>
      <description>Paige,&lt;BR /&gt;
&lt;BR /&gt;
Not quite, you compare the observations with each other and select the ones that meet the above criteria. Those with unique SA values will definitely be selected.</description>
      <pubDate>Mon, 11 Oct 2010 20:33:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15126#M2596</guid>
      <dc:creator>EMKBB</dc:creator>
      <dc:date>2010-10-11T20:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Selection</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15127#M2597</link>
      <description>Given the OP input, what needs to be looked-at are FIRST.&lt;BREAK_VARIABLE&gt;  and LAST.&lt;BREAK_VARIABLE&gt; with "BY GROUP PROCESSING", and possibly using the LAG function, or using a RETAIN statement to capture/retain the prior observation variable/value for comparison to the current variable/value.  Take the challenge in smaller components, dealing with each comparison task individually, validate your own developed code (based on available DOC and forum input), and build on the process with each additional comparison rqmt.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/BREAK_VARIABLE&gt;&lt;/BREAK_VARIABLE&gt;</description>
      <pubDate>Tue, 12 Oct 2010 00:59:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15127#M2597</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-10-12T00:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Selection</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15128#M2598</link>
      <description>Thanks sbb, I will look it up.</description>
      <pubDate>Tue, 12 Oct 2010 04:19:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15128#M2598</guid>
      <dc:creator>EMKBB</dc:creator>
      <dc:date>2010-10-12T04:19:05Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Selection</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15129#M2599</link>
      <description>If you want to use SQL the look up "group by" with a "having" clause</description>
      <pubDate>Tue, 12 Oct 2010 11:51:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15129#M2599</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-10-12T11:51:15Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Selection</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15130#M2600</link>
      <description>Thanks Patrick.</description>
      <pubDate>Tue, 12 Oct 2010 12:30:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15130#M2600</guid>
      <dc:creator>EMKBB</dc:creator>
      <dc:date>2010-10-12T12:30:13Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Selection</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15131#M2601</link>
      <description>&amp;gt; Not quite, you compare the observations with each&lt;BR /&gt;
&amp;gt; other and select the ones that meet the above&lt;BR /&gt;
&amp;gt; criteria. Those with unique SA values will definitely&lt;BR /&gt;
&amp;gt; be selected.&lt;BR /&gt;
&lt;BR /&gt;
So please give an example, or explain more thoroughly, exactly what you are looking for. I specifically asked (and you didn't reply):&lt;BR /&gt;
&lt;BR /&gt;
Are you comparing all observations to each other? Or selected pairs (triples/quads/etc.) only? If so, how are you selecting the pairs?</description>
      <pubDate>Tue, 12 Oct 2010 14:22:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15131#M2601</guid>
      <dc:creator>Paige</dc:creator>
      <dc:date>2010-10-12T14:22:21Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Selection</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15132#M2602</link>
      <description>Sorry Paige, if I was not explanatory enough, here we go:&lt;BR /&gt;
&lt;BR /&gt;
In the table below, Observation 1 and Observation 5 have the same SA value, but the DA value of Observation 1 is greater than that of Observation 5 so in reading the data, Observation 1 will be selected but Observation 5 will be dropped.&lt;BR /&gt;
&lt;BR /&gt;
Again Observation 2 and Observation 13 have the same SA values, and incidentally their AD values are also the same, so here we resort to their RS values (which are not the same). The RS value of Observation 13 is higher, so it will be selected and Observation 2 dropped.&lt;BR /&gt;
&lt;BR /&gt;
Observations with unique SA values will be selected.&lt;BR /&gt;
&lt;BR /&gt;
Observations 4, 7, 8, 12 will not be selected because they have the values Tl,  Ng, Yd and Tl respectively.&lt;BR /&gt;
&lt;BR /&gt;
Observation	SA	AD	RS	SP&lt;BR /&gt;
1	                15	20	19	Bt&lt;BR /&gt;
2	                18	21	22	Ab&lt;BR /&gt;
3	                16	18	16	Ab&lt;BR /&gt;
4	                10	12	15	Tl&lt;BR /&gt;
5	                15	19	17	Bt&lt;BR /&gt;
6	                20	22	24	Ef&lt;BR /&gt;
7	               13	16	17	Ng&lt;BR /&gt;
8	               26	27	29	Yd&lt;BR /&gt;
9	               22	23	26	Ef&lt;BR /&gt;
10	               24	26	28	Dd&lt;BR /&gt;
11	               23	25	27	Bt&lt;BR /&gt;
12	               27	29	30	Tl&lt;BR /&gt;
13	               18	21	23	Ef&lt;BR /&gt;
14	               21	22	25	Ab&lt;BR /&gt;
15	              12	14	16	Dd</description>
      <pubDate>Tue, 12 Oct 2010 14:59:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15132#M2602</guid>
      <dc:creator>EMKBB</dc:creator>
      <dc:date>2010-10-12T14:59:57Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Selection</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15133#M2603</link>
      <description>Okay, I understand now. What is it about my PROC SORT suggestion that doesn't work? Seems to me it puts your data in the proper order and makes it easy for you to select the ones you want.</description>
      <pubDate>Tue, 12 Oct 2010 16:38:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15133#M2603</guid>
      <dc:creator>Paige</dc:creator>
      <dc:date>2010-10-12T16:38:02Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Selection</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15134#M2604</link>
      <description>Paige is right. And if - for some reason you didn't specify - the original observation order needs to be preserved then add some kind of observation number up front, then proceed as Paige suggested and finally sort the remaining observations back.</description>
      <pubDate>Wed, 13 Oct 2010 07:20:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15134#M2604</guid>
      <dc:creator>Robert_Bardos</dc:creator>
      <dc:date>2010-10-13T07:20:36Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Selection</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15135#M2605</link>
      <description>I do it roughly, And i think there is some way can optimize it.&lt;BR /&gt;
But I have to leave for the sake of working.&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Yes.Paige has the right idea here.&lt;BR /&gt;
try it.'nodupkey' can keep the first duplicate observation.&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data temp(where=( sp not in('Yd' 'TI' 'Ng')));&lt;BR /&gt;
 input Obs SA AD RS SP $;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 15 20 19 Bt&lt;BR /&gt;
2 18 21 22 Ab&lt;BR /&gt;
3 16 18 16 Ab&lt;BR /&gt;
4 10 12 15 Tl&lt;BR /&gt;
5 15 19 17 Bt&lt;BR /&gt;
6 20 22 24 Ef&lt;BR /&gt;
7 13 16 17 Ng&lt;BR /&gt;
8 26 27 29 Yd&lt;BR /&gt;
9 22 23 26 Ef&lt;BR /&gt;
10 24 26 28 Dd&lt;BR /&gt;
11 23 25 27 Bt&lt;BR /&gt;
12 27 29 30 Tl&lt;BR /&gt;
13 18 21 23 Ef&lt;BR /&gt;
14 21 22 25 Ab&lt;BR /&gt;
15 12 14 16 Dd &lt;BR /&gt;
;&lt;BR /&gt;
proc sort data=temp ;&lt;BR /&gt;
 by sa descending ad descending rs;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sort data=temp nodupkey;&lt;BR /&gt;
 by sa;&lt;BR /&gt;
run;&lt;BR /&gt;
proc print noobs;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Ksharp

Message was edited by: Ksharp</description>
      <pubDate>Mon, 18 Oct 2010 01:00:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-Selection/m-p/15135#M2605</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2010-10-18T01:00:55Z</dc:date>
    </item>
  </channel>
</rss>

