<?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: Apply logic based on waterfall for unique ids in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Apply-logic-based-on-waterfall-for-unique-ids/m-p/363693#M274948</link>
    <description>&lt;P&gt;Read all the 'Yes' values, determining the prime yes (i.e. A=yes supersedes B=yes &amp;gt;&amp;gt; E=yes &amp;gt;&amp;gt; C=yes &amp;gt;&amp;gt; D=yes).&amp;nbsp; Then read all the cases turning everything to No except the prime yes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In other words if an ID starts out with&amp;nbsp;3 Yes's and 2 No's, the 3 Yes's are read first [see the "where=(preference='Yes')" parameter] to determine the prime yes.&amp;nbsp; Then all 5 Yes's and No's are read, assigning No to all but the prime yes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input UNIQUE_ID        CODE :$1.          Preference :$3.;
datalines;
1 A Yes
1 B no
2 B Yes
2 C no
3 C no
3 D no
3 E Yes
run;

data want (drop=prime_rank);
  set have (in=inyes where=(preference='Yes'))
      have (in=inkeep);
  by unique_id;
  if first.unique_id then prime_rank=.;
  retain prime_rank;

  if inyes then do;
    prime_rank=min(prime_rank,findc('ABEDC',code));
    delete;  /* Delete this case, it will be read again, and output below */
  end;
  if NOT(code=CHAR('ABEDC',prime_rank) and preference='Yes') then preference='No';
run;
&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Jun 2017 04:21:28 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2017-06-02T04:21:28Z</dc:date>
    <item>
      <title>Apply logic based on waterfall for unique ids</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Apply-logic-based-on-waterfall-for-unique-ids/m-p/363662#M274946</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;i have a sample dataset where i need to apply logic to unique_id as per code it has in waterfall manner.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For instance if for unique ID 1, &amp;nbsp;Code A is found which gets Yes in preference then other instance of unique ID 1 will get "no" in Preference column&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;for unique ID 2&amp;nbsp;Code B&amp;nbsp;is found which gets Yes in preference&amp;nbsp;then other instance of unique ID 2&amp;nbsp;will get "no" in Preference column&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;for unique ID 3&amp;nbsp;Code E&amp;nbsp;is found which gets Yes in preference &amp;nbsp;then other instance of unique ID 3&amp;nbsp;will get "no" in Preference column&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;so waterfall for Code follows the order as A,B,E,D,C.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;So A gets first prefernce if found for unique id,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;B gets second and so on&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;How can i apply this waterfall for unique id. So in nutshell if i find a code for unique id as per Waterfall it should get Yes in preference and rest all other instance of same unique id get No in preference.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;UNIQUE_ID &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CODE &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Preference&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;A &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Yes&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; no&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;B &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Yes&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;no&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;C &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;no&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;D &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;no&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;E &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Yes&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2017 00:43:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Apply-logic-based-on-waterfall-for-unique-ids/m-p/363662#M274946</guid>
      <dc:creator>sasuser101</dc:creator>
      <dc:date>2017-06-02T00:43:36Z</dc:date>
    </item>
    <item>
      <title>Re: Apply logic based on waterfall for unique ids</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Apply-logic-based-on-waterfall-for-unique-ids/m-p/363678#M274947</link>
      <description>&lt;P&gt;Create a custom format that maps the order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ABEDC&lt;/P&gt;
&lt;P&gt;Then A-&amp;gt;1&lt;/P&gt;
&lt;P&gt;B-&amp;gt;2&lt;/P&gt;
&lt;P&gt;E-&amp;gt;3&lt;/P&gt;
&lt;P&gt;D-&amp;gt;4&lt;/P&gt;
&lt;P&gt;C-&amp;gt;5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sort by the new variable and use BY groups to identify the first.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p0e9b2d12lpyjkn1b0y1tqg6q146.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p0e9b2d12lpyjkn1b0y1tqg6q146.htm&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2017 02:42:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Apply-logic-based-on-waterfall-for-unique-ids/m-p/363678#M274947</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-06-02T02:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: Apply logic based on waterfall for unique ids</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Apply-logic-based-on-waterfall-for-unique-ids/m-p/363693#M274948</link>
      <description>&lt;P&gt;Read all the 'Yes' values, determining the prime yes (i.e. A=yes supersedes B=yes &amp;gt;&amp;gt; E=yes &amp;gt;&amp;gt; C=yes &amp;gt;&amp;gt; D=yes).&amp;nbsp; Then read all the cases turning everything to No except the prime yes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In other words if an ID starts out with&amp;nbsp;3 Yes's and 2 No's, the 3 Yes's are read first [see the "where=(preference='Yes')" parameter] to determine the prime yes.&amp;nbsp; Then all 5 Yes's and No's are read, assigning No to all but the prime yes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input UNIQUE_ID        CODE :$1.          Preference :$3.;
datalines;
1 A Yes
1 B no
2 B Yes
2 C no
3 C no
3 D no
3 E Yes
run;

data want (drop=prime_rank);
  set have (in=inyes where=(preference='Yes'))
      have (in=inkeep);
  by unique_id;
  if first.unique_id then prime_rank=.;
  retain prime_rank;

  if inyes then do;
    prime_rank=min(prime_rank,findc('ABEDC',code));
    delete;  /* Delete this case, it will be read again, and output below */
  end;
  if NOT(code=CHAR('ABEDC',prime_rank) and preference='Yes') then preference='No';
run;
&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;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Jun 2017 04:21:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Apply-logic-based-on-waterfall-for-unique-ids/m-p/363693#M274948</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-06-02T04:21:28Z</dc:date>
    </item>
  </channel>
</rss>

