<?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: Find the max and unique value by index in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-the-max-and-unique-value-by-index/m-p/494606#M130365</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input rownum	check;
cards;
6	0.66667
6	0.81818
7	0.5
7	1
7	0.75
8	0.5
8	0.75
28	1
28	1
;

proc sql;
create table want as
select *,(sum(check=1)=1)*(check=1) as output
from have
group by rownum;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 11 Sep 2018 18:57:48 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-09-11T18:57:48Z</dc:date>
    <item>
      <title>Find the max and unique value by index</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-max-and-unique-value-by-index/m-p/494600#M130360</link>
      <description>&lt;P&gt;I am trying to find: for each same rownum, if check=1 and is the only 1 for that rownum, then output =1, otherwise output =0.&lt;/P&gt;&lt;P&gt;Here below is a data example:&lt;/P&gt;&lt;P&gt;Data have&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;rownum&lt;/TD&gt;&lt;TD&gt;check&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;0.66667&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;0.81818&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;0.5&lt;/TD&gt;&lt;/TR&gt;&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gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;0.5&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;0.75&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;28&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;28&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please let me know how to get the desired output, thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 11 Sep 2018 18:41:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-max-and-unique-value-by-index/m-p/494600#M130360</guid>
      <dc:creator>lpy0521</dc:creator>
      <dc:date>2018-09-11T18:41:15Z</dc:date>
    </item>
    <item>
      <title>Re: Find the max and unique value by index</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-max-and-unique-value-by-index/m-p/494603#M130363</link>
      <description>&lt;P&gt;If the data are sorted by rownum:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=n_ones);
  set have (where=(check=1) in=hasones)
      have (in=inall);
  by rownum;
  if first.rownum then n_ones=0;
  n_ones+hasones;
  if inall;
  output=(check=1 and n_ones=1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For each rownum this data step (1) reads and counts all instances of check=1, (2) reads all records (including re-reading the check=1 recs) for the rownum.&amp;nbsp; It only keeps records from the second group, but at that point it is possible to retrieve the count of ones and set the output variable.&lt;/P&gt;</description>
      <pubDate>Tue, 11 Sep 2018 18:51:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-max-and-unique-value-by-index/m-p/494603#M130363</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-09-11T18:51:29Z</dc:date>
    </item>
    <item>
      <title>Re: Find the max and unique value by index</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-the-max-and-unique-value-by-index/m-p/494606#M130365</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input rownum	check;
cards;
6	0.66667
6	0.81818
7	0.5
7	1
7	0.75
8	0.5
8	0.75
28	1
28	1
;

proc sql;
create table want as
select *,(sum(check=1)=1)*(check=1) as output
from have
group by rownum;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Sep 2018 18:57:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-the-max-and-unique-value-by-index/m-p/494606#M130365</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-11T18:57:48Z</dc:date>
    </item>
  </channel>
</rss>

