<?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: Getting a single value for each group in values ties situation using proc SQL in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484395#M71823</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;: Yes I have identified a case where it doesn't work .. the first one ID=ABC101.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I correctly understand&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/203751"&gt;@Saurabh291989&lt;/a&gt;'s latest post, it should have a count of 5, where your code results in a count of 4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, here is an example that uses the above dataset, but adds the new example that was included in&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/203751"&gt;@Saurabh291989&lt;/a&gt;'s latest post. Your code produces a count of 1, rather than 4, for that new example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data xyz;
  input ID:$6.  Symbol:$2. @@;
  datalines;
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC101 QP
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
ABC105 XY
ABC105 PQ
ABC105 YX
ABC105 AB
;
run;

data want;
/*initilise hash object with key vars id and symbol and count as data var */
 if _n_ = 1 then do;
   declare hash h();
   h.defineKey('id','symbol');
   h.definedata('count');
   h.defineDone();
 end;
/*first pass of the dataset to get the count of combination of id and symbol
 and load in the hash object*/
do until (l);
   set xyz end=l;
  if h.find() ne 0 then do;count=1;h.replace();end;
  else do;count=count+1;h.replace();end;
end; 
l=0;
/*second pass using doubl DOW, 1st dow to get the max of all combinations
with id */
do until(l);
    m=.;
    do until(last.id);
        set xyz end=l;
        by id;
        rc=h.find();
        m=max(count,m);
    end; 
        f=0;
/*this will output the required max top value if ties or 
just the max if no ties within an id group*/
    do until(last.id);
        set xyz ;
        by id;  
        rc=h.find();
        if m=count and  not f then do; output;f=1;end;
    end;
end;
keep id symbol count;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which results in the following:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 446px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22254i4E34B4E08ADB5F0B/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 06 Aug 2018 14:51:40 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2018-08-06T14:51:40Z</dc:date>
    <item>
      <title>Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484020#M71776</link>
      <description>&lt;P&gt;I stuck in a situation in an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class="language-sas"&gt;data xyz;
input ID:$6.  Symbol:$2. @@;
datalines;
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
;
run;
proc sql feedback;
select *, count(ID) as Total from Work.xyz group by Symbol, ID;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;OUTPUT:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Output of above select query." style="width: 218px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22221i995F3BB975ABE904/image-size/large?v=v2&amp;amp;px=999" role="button" title="TABLE_TEST_02.jpg" alt="Output of above select query." /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Output of above select query.&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Instead of the above output, I want only this one as output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="For each group, I want only a single row when values of total column gets tied." style="width: 212px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/22222i9FA9B7ACEC53DC6F/image-size/large?v=v2&amp;amp;px=999" role="button" title="TABLE_TEST_01.jpg" alt="For each group, I want only a single row when values of total column gets tied." /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;For each group, I want only a single row when values of total column gets tied.&lt;/span&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note: I need a solution for 1 million data, above is just an example. Total value can be different.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Someone help me out.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Aug 2018 14:26:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484020#M71776</guid>
      <dc:creator>Saurabh291989</dc:creator>
      <dc:date>2018-08-04T14:26:33Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484021#M71777</link>
      <description>&lt;P&gt;It's impossible to provide a generalized solution without more information.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are the 2nd symbol values always mirror images of the first symbol value (example: UV and VU)?&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Can there be more than one mirror image pair of symbols in a given ID? (For example, can ABC104 have UV and VU and BG and GB and TR and RT?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are the letters in the symbols always adjacent to one another in the alphabet? (V is adjacent to U, but can V appear with A?)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does this solution HAVE to be in SQL? Because even if you say "YES", I would likely provide a non-SQL solution if I think of one.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Aug 2018 13:49:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484021#M71777</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-08-04T13:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484022#M71778</link>
      <description>&lt;P&gt;Diagnose it. That is because you have the following distinct combinations&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;proc sql ;&lt;BR /&gt;&lt;STRONG&gt;select distinct id, symbol from xyz;&lt;/STRONG&gt;&lt;BR /&gt;*select *, count(ID) as Total from Work.xyz group by Symbol, ID;&lt;BR /&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID Symbol&lt;BR /&gt; ƒƒƒƒƒƒƒƒƒƒƒƒƒƒ&lt;BR /&gt; ABC101 XY&lt;BR /&gt; ABC101 YX&lt;BR /&gt; ABC102 PQ&lt;BR /&gt; ABC102 QP&lt;BR /&gt; ABC103 IJ&lt;BR /&gt; ABC103 JI&lt;BR /&gt; ABC104 UV&lt;BR /&gt; ABC104 VU&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;So you basically have 8 different groups as a combination of id and symbol&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Aug 2018 13:57:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484022#M71778</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-04T13:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484024#M71779</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13573"&gt;@Paige&lt;/a&gt; Miller&lt;BR /&gt;No, letters in the symbol are not adjacent. They're random in nature. The combination can be any within 26 alphabets and alphanumeric.&lt;BR /&gt;&lt;BR /&gt;I would like to prefer any other non-SQL if there is no solution for SQL.&lt;BR /&gt;Provide me the solution, Miller.</description>
      <pubDate>Sat, 04 Aug 2018 14:17:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484024#M71779</guid>
      <dc:creator>Saurabh291989</dc:creator>
      <dc:date>2018-08-04T14:17:22Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484025#M71780</link>
      <description>&lt;P&gt;I think SQL permits SUBSTR.&amp;nbsp; If so, add to the SELECT statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where substr(symbol, 1, 1) &amp;lt;= substr(symbol, 2, 1)&lt;/P&gt;</description>
      <pubDate>Sat, 04 Aug 2018 14:17:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484025#M71780</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-08-04T14:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484026#M71781</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&lt;BR /&gt;&lt;BR /&gt;I know that there are 8 different groups as a combination of id and symbol. But I want only topmost count(Total) value for each id and if count values get tied in each group then it returns only top row i.e. 1st one.</description>
      <pubDate>Sat, 04 Aug 2018 14:24:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484026#M71781</guid>
      <dc:creator>Saurabh291989</dc:creator>
      <dc:date>2018-08-04T14:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484030#M71782</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data xyz;
input ID:$6.  Symbol:$2. @@;
datalines;
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
ABC104 VU
;
run;
/*i added one more row to test for non ties ABC104 VU */


/*if count values get tied in each group then it returns only top row i.e. 1st one,
since proc sql order is not guaranteed,creating a counter column n to the dataset "as is".*/
data temp;
set xyz;
by id;
if first.id then n=1;
else n+1;
run;

proc sql;
create table want(drop=n f) as
select *, case when std(total)=0 then  min(n) else max(total) end as f
from
(select *, count(ID) as Total from Work.temp group by Symbol, ID	
having n=min(n))
group by id
having (n=f) or (f=total);
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Aug 2018 16:30:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484030#M71782</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-04T16:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484031#M71783</link>
      <description>&lt;P&gt;I also added an extra record and, with my test data,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;'s code didn't produce the desired result. The following requires an extra pass of the data, but with only a million records, shouldn't take very long:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data xyz;
  input ID:$6.  Symbol:$2. @@;
  datalines;
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC101 QP
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
;
run;

data for4mat (drop=i j k);
  retain fmtname 'symbols' type 'C';
  length start $2;
  length label $2;
  array astart(36) $2 _temporary_;
  do i=65 to 90,48 to 57;
    j+1;
    astart(j)=byte(i);
  end;
  k=0;
  do i=1 to 36;
    do j=i+1 to 36;
      start=catt(astart(i),astart(j));
      label=catt(astart(i),astart(j));
      output;
      start=catt(astart(j),astart(i));
      label=catt(astart(i),astart(j));
      output;
    end;
  end;
run;

proc format cntlin = for4mat;
run;

data need;
  set xyz;
  length symbol2 $2;
  symbol2=put(symbol,$symbols.);
run;

data need (drop=symbol2 test);
  set need;
  by id symbol2 notsorted;
  length test $2;
  retain test;
  if first.symbol2 then test=symbol;
  if symbol eq test;
run;
  
proc sql;
  create table want as
    select distinct *, count(ID) as Total
      from need
        group by ID, Symbol
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 04 Aug 2018 16:40:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484031#M71783</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-08-04T16:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484032#M71784</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&amp;nbsp;and sorry to bother with a request on a weekend, would a tweak&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;having (n=f) or (f=total and n=min(n)); suffice?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;EDITED after some serious test: Won't suffice if there is another combination at n=1.. Pardon me.Sorry about that&lt;/P&gt;</description>
      <pubDate>Sat, 04 Aug 2018 17:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484032#M71784</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-04T17:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484033#M71785</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/203751"&gt;@Saurabh291989&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13573"&gt;@Paige&lt;/a&gt; Miller&lt;BR /&gt;No, letters in the symbol are not adjacent. They're random in nature. The combination can be any within 26 alphabets and alphanumeric.&lt;BR /&gt;&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So I asked you to clarify four different points regarding your data, and you clarified one of the four.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Aug 2018 17:15:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484033#M71785</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-08-04T17:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484075#M71790</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data xyz;
  input ID:$6.  Symbol:$2. @@;
  datalines;
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC101 QP
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
;
run;

data want;
 
 if _n_ = 1 then do;
   declare hash h();
   h.defineKey('id','symbol');
   h.definedata('count');
   h.defineDone();
 end;

do until (l);
   set xyz end=l;
  if h.find() ne 0 then do;count=1;h.replace();end;
  else do;count=count+1;h.replace();end;
end; 
l=0;
do until(l);
	m=.;
	do until(last.id);
		set xyz end=l;
		by id;
		rc=h.find();
 		m=max(count,m);
	end; 
		f=0;
	do until(last.id);
		set xyz ;
		by id;	
		rc=h.find();
		if m=count and  not f then do; output;f=1;end;
	end;
end;
keep id symbol count;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 04 Aug 2018 23:55:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484075#M71790</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-04T23:55:45Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484077#M71791</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;: Your code needs an adjustment as it's losing the fifth record, i.e.:&amp;nbsp;ABC101 QP&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Interestingly, on the small test file, my approach runs faster. Be interesting to see how the two approaches compare on a million record file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 00:43:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484077#M71791</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-08-05T00:43:56Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484078#M71792</link>
      <description>&lt;P&gt;Good evening&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&amp;nbsp;my understanding is that you can't have duplicate ID in your result and the code is supposed to check for max of counts of combination of groups and pick the earliest group combination within an ID that has max of the counts. Your code is picking two different counts for the same ID ABC101. I am not sure if that is what is desired.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically,if my understanding is correct , the algorithm would have to check for&lt;/P&gt;
&lt;P&gt;1. compute the counts with combination of id, symbol group by&lt;/P&gt;
&lt;P&gt;2. get the max of counts within a group id&amp;nbsp; and not combination&lt;/P&gt;
&lt;P&gt;3. if no ties, easy pick that else pick the earliest combination that satisfies the max count&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ABC101 QP has a count of 1 whilst other ABC101 has greater counts. So i think that anyway doesn't meet the max count need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS&lt;/P&gt;
&lt;P&gt;It always makes me nervous to to be&amp;nbsp; part of thread where champs like you are part of. Sorry if any of the above doesn't make sense&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 01:07:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484078#M71792</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-08-05T01:07:39Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484080#M71793</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;: Makes perfect sense! Either you're right, I am, or neither of us are.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't be nervous! You have picked up so much in the short time you've been using/learning SAS that one would be hard pressed to distinguish your posts from any of the old timers. In fact, your code has often been the best proposed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 05 Aug 2018 01:32:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484080#M71793</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-08-05T01:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484134#M71795</link>
      <description>&lt;P&gt;Is it that necessary to use SQL ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data xyz;
input ID:$6.  Symbol:$2. @@;
datalines;
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
;
run;
proc sql feedback number;
select * from
(select *, count(ID) as Total from Work.xyz group by Symbol, ID)
group by id
having symbol=min(symbol);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Aug 2018 11:25:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484134#M71795</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-08-05T11:25:19Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484315#M71812</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13573"&gt;@Paige&lt;/a&gt; Miller:&lt;BR /&gt;Apology for the delay:&lt;BR /&gt;&lt;BR /&gt;1) No, 2nd symbol value is not the mirror images of the 1st symbol.&lt;BR /&gt;2) Yes, there are approx. 100-1000k mirror image pair of symbols in a given ID.&lt;BR /&gt;3) Nope, the letters in the symbols always not adjacent to one another in the alphabet.&lt;BR /&gt;4) Actually, this query has to resolve with the proc SQL but I'll take the chance with the Non-SQL solution.</description>
      <pubDate>Mon, 06 Aug 2018 11:33:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484315#M71812</guid>
      <dc:creator>Saurabh291989</dc:creator>
      <dc:date>2018-08-06T11:33:29Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484317#M71813</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;:&lt;BR /&gt;&lt;BR /&gt;Sorry, buddy! it didn't work.</description>
      <pubDate>Mon, 06 Aug 2018 11:35:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484317#M71813</guid>
      <dc:creator>Saurabh291989</dc:creator>
      <dc:date>2018-08-06T11:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484321#M71814</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;:&lt;BR /&gt;Yes, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;, you understood my problem correctly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your quotes:&lt;/P&gt;&lt;P&gt;"&amp;nbsp;Basically,if my understanding is correct , the algorithm would have to check for&lt;/P&gt;&lt;P&gt;1. compute the counts with combination of id, symbol group by&lt;/P&gt;&lt;P&gt;2. get the max of counts within a group id&amp;nbsp; and not combination&lt;/P&gt;&lt;P&gt;3. if no ties, easy pick that else pick the earliest combination that satisfies the max count"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That's what I'm looking for.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2018 12:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484321#M71814</guid>
      <dc:creator>Saurabh291989</dc:creator>
      <dc:date>2018-08-06T12:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484356#M71819</link>
      <description>&lt;P&gt;Just have one question: given the following example dataset, what result would you expect for ID=ABC101?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data xyz;
  input ID:$6.  Symbol:$2. @@;
  datalines;
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC101 XY ABC101 YX
ABC101 QP
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC102 PQ ABC102 QP
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC103 IJ ABC103 JI
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
ABC104 UV ABC104 VU
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Aug 2018 13:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484356#M71819</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-08-06T13:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: Getting a single value for each group in values ties situation using proc SQL</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484364#M71820</link>
      <description>@ art297:&lt;BR /&gt;Actually, I'm looking for the topmost value for the ABC101 i.e. it doesn't matter whether it is XY, YX or QP. Only matters, it should be maxed in the count and if a group count values tie, it selects only the 1st value.&lt;BR /&gt;example:&lt;BR /&gt;ID SYMBOL COUNT&lt;BR /&gt;ABC101 XY 4&lt;BR /&gt;ABC101 PQ 4&lt;BR /&gt;ABC101 YX 4&lt;BR /&gt;ABC101 AB 4&lt;BR /&gt;&lt;BR /&gt;if this situation arrived only top value showed up in the result i.e. ABC101 XY 4</description>
      <pubDate>Mon, 06 Aug 2018 13:56:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Getting-a-single-value-for-each-group-in-values-ties-situation/m-p/484364#M71820</guid>
      <dc:creator>Saurabh291989</dc:creator>
      <dc:date>2018-08-06T13:56:27Z</dc:date>
    </item>
  </channel>
</rss>

