<?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: how to do roll-ups and remove duplicates? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354964#M83106</link>
    <description>&lt;P&gt;By doing summing, there are still duplicates. I think it is not summing up, it is rolling up. For e.g.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dist&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; terr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;relid&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mkt&amp;nbsp;&amp;nbsp; product&amp;nbsp;&amp;nbsp; TR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NR&lt;/P&gt;&lt;P&gt;101&amp;nbsp;&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;&amp;nbsp;&amp;nbsp; 210&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; XI_U&amp;nbsp;&amp;nbsp;&amp;nbsp; XIA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 100&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;101&amp;nbsp;&amp;nbsp;&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;&amp;nbsp; 212&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; XI_U&amp;nbsp;&amp;nbsp; XIA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 60&lt;/P&gt;&lt;P&gt;101&amp;nbsp;&amp;nbsp;&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;&amp;nbsp; 212&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; XI_U&amp;nbsp;&amp;nbsp; XIA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 60&lt;/P&gt;&lt;P&gt;101&amp;nbsp;&amp;nbsp;&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;&amp;nbsp; 213&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; XI_U&amp;nbsp;&amp;nbsp; XIA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;110&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 70&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to have only one row per terr per product. So in the above example, it is having duplicate for Terr 2, so I should remove that duplicate and sum Relid 212 and 213.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for the confusion and thanks a lot for all of your comments.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Malathi&lt;/P&gt;</description>
    <pubDate>Mon, 01 May 2017 15:21:55 GMT</pubDate>
    <dc:creator>Malathi13</dc:creator>
    <dc:date>2017-05-01T15:21:55Z</dc:date>
    <item>
      <title>how to do roll-ups and remove duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354930#M83090</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a table like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;dist&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;terr&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;relid&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;mkt&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;product&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;TR&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;NR&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;101&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;210&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;XI_U&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;XIA&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;100&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;0&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;101&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;211&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;XI_U&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;XIA&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;0&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;60&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;101&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;212&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;XI_U&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;XIA&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;110&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;70&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;101&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;1&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;213&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;XI_U&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;XIA&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;112&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;80&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;101&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;2&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;214&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;XI_U&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;XIA&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;115&lt;/FONT&gt;&lt;/TD&gt;&lt;TD&gt;&lt;FONT color="#000000" face="Calibri" size="3"&gt;91&lt;/FONT&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to have the roll-ups of all the same terr and remove duplicates: For e.g. for dist 101 and terr 1 I should have only one row with TR=322 and NR=150. How do I remove duplicates and roll up the values as per the terr for the dist. In this case there should be only two rows (dist 101 and Terr1 and Dist 101 and terr2).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to remove the duplicates using nodupkey in proc sort but that removes some of the products (not shown here).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;M&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 14:13:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354930#M83090</guid>
      <dc:creator>Malathi13</dc:creator>
      <dc:date>2017-05-01T14:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to do roll-ups and remove duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354942#M83092</link>
      <description>&lt;P&gt;like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input dist terr relid mkt $ product $ TR NR;
datalines;
101 1 210 XI_U XIA 100 0 
101 2 211 XI_U XIA 0 60 
101 1 212 XI_U XIA 110 70 
101 1 213 XI_U XIA 112 80 
101 2 214 XI_U XIA 115 91 
;

proc sort data = have;
	by dist terr;
run;

data want;
	set have;
	by dist terr;
	if first.dist and first.terr then do; 
		sum_TR=0;
		sum_NR=0;
	end;
	
	sum_TR = sum_TR + TR;
	sum_NR = sum_NR + NR;

	if last.terr then output;

	retain sum_TR sum_NR 0;
	drop TR NR;

run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 May 2017 14:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354942#M83092</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-05-01T14:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: how to do roll-ups and remove duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354943#M83093</link>
      <description>&lt;P&gt;It appears that you are SUMMING variables TR and NR. What values, if any of RELID, MKT or Product should be with the output?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you looking for a REPORT or a Dataset?&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 14:27:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354943#M83093</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-05-01T14:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: how to do roll-ups and remove duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354949#M83097</link>
      <description>&lt;P&gt;Assuming what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;is saying is true in that your purpose is to sum, and you are grouping by terr, then here is a relatively simple solution in proc sql (there are many ways do this but this is one):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input dist terr relid mkt $ product $ TR NR;
datalines;
101 1 210 XI_U XIA 100 0 
101 2 211 XI_U XIA 0 60 
101 1 212 XI_U XIA 110 70 
101 1 213 XI_U XIA 112 80 
101 2 214 XI_U XIA 115 91 
;

PROC SQL;
CREATE TABLE WANT AS
SELECT TERR, SUM(TR) AS TOTAL_TR, SUM(NR) AS TOTAL_NR
FROM HAVE
GROUP BY TERR;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 May 2017 14:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354949#M83097</guid>
      <dc:creator>thomp7050</dc:creator>
      <dc:date>2017-05-01T14:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to do roll-ups and remove duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354953#M83099</link>
      <description>&lt;P&gt;By "rollup" you apparently meain you want to sum TR and NR for each combination of DIST and TERR.&amp;nbsp; But product and MKT appear to be constants that you might want to keep in the output.&amp;nbsp;, so I include them in the CLASS statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That is what PROC SUMMARY is for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc summary data=have nway;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; class dist terr mkt product;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; var tr nr;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output out=want&amp;nbsp;&amp;nbsp; sum(tr nr)=tr_sum nr_sum;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also use proc summary to get other stats (N min max mean std ...... ).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 14:49:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354953#M83099</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-05-01T14:49:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to do roll-ups and remove duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354955#M83101</link>
      <description>&lt;P&gt;I'm trying to generate a report.&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 14:52:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354955#M83101</guid>
      <dc:creator>Malathi13</dc:creator>
      <dc:date>2017-05-01T14:52:15Z</dc:date>
    </item>
    <item>
      <title>Re: how to do roll-ups and remove duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354964#M83106</link>
      <description>&lt;P&gt;By doing summing, there are still duplicates. I think it is not summing up, it is rolling up. For e.g.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dist&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; terr&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;relid&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;mkt&amp;nbsp;&amp;nbsp; product&amp;nbsp;&amp;nbsp; TR&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NR&lt;/P&gt;&lt;P&gt;101&amp;nbsp;&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;&amp;nbsp;&amp;nbsp; 210&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; XI_U&amp;nbsp;&amp;nbsp;&amp;nbsp; XIA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 100&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;101&amp;nbsp;&amp;nbsp;&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;&amp;nbsp; 212&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; XI_U&amp;nbsp;&amp;nbsp; XIA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 60&lt;/P&gt;&lt;P&gt;101&amp;nbsp;&amp;nbsp;&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;&amp;nbsp; 212&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; XI_U&amp;nbsp;&amp;nbsp; XIA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 60&lt;/P&gt;&lt;P&gt;101&amp;nbsp;&amp;nbsp;&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;&amp;nbsp; 213&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; XI_U&amp;nbsp;&amp;nbsp; XIA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;110&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 70&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to have only one row per terr per product. So in the above example, it is having duplicate for Terr 2, so I should remove that duplicate and sum Relid 212 and 213.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for the confusion and thanks a lot for all of your comments.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Malathi&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 15:21:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354964#M83106</guid>
      <dc:creator>Malathi13</dc:creator>
      <dc:date>2017-05-01T15:21:55Z</dc:date>
    </item>
    <item>
      <title>Re: how to do roll-ups and remove duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354965#M83107</link>
      <description>&lt;P&gt;My output should have dist, mkt, product, TR and NR. Don't need relid and Terr but the duplicates should be taken off by relid.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;M&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 15:24:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354965#M83107</guid>
      <dc:creator>Malathi13</dc:creator>
      <dc:date>2017-05-01T15:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: how to do roll-ups and remove duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354979#M83115</link>
      <description>&lt;P&gt;One thing: if you roll up like this then you will always have one row per distinct response. &amp;nbsp;If you wish to include relid in with the rest of the responses then you will get one row per terr/relid, which may not be what you're looking for? &amp;nbsp;If you just wanted one row per terr then you could not include relid, as such:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input dist terr relid mkt $ product $ TR NR;
datalines;
101 1 210 XI_U XIA 100 0 
101 2 211 XI_U XIA 0 60 
101 1 212 XI_U XIA 110 70 
101 1 213 XI_U XIA 112 80 
101 2 214 XI_U XIA 115 91 
;

PROC SQL;
CREATE TABLE WANT AS
SELECT dist, TERR,  MKT, SUM(TR) AS TOTAL_TR, SUM(NR) AS TOTAL_NR
FROM HAVE
GROUP BY dist, TERR, MKT ;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Alternatively, you could&amp;nbsp;count the distinct relids per terr if you wanted.&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 17:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354979#M83115</guid>
      <dc:creator>thomp7050</dc:creator>
      <dc:date>2017-05-01T17:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: how to do roll-ups and remove duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354986#M83120</link>
      <description>&lt;P&gt;You are right,&lt;/P&gt;&lt;P&gt;I'm not going to include relid and terr as well in the final output.&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 17:23:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354986#M83120</guid>
      <dc:creator>Malathi13</dc:creator>
      <dc:date>2017-05-01T17:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: how to do roll-ups and remove duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354992#M83124</link>
      <description>&lt;P&gt;In that case, does the solution that I have above work for you?&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 17:39:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354992#M83124</guid>
      <dc:creator>thomp7050</dc:creator>
      <dc:date>2017-05-01T17:39:52Z</dc:date>
    </item>
    <item>
      <title>Re: how to do roll-ups and remove duplicates?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354993#M83125</link>
      <description>&lt;P&gt;So, product should not be included in teh select statement?&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 17:42:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-do-roll-ups-and-remove-duplicates/m-p/354993#M83125</guid>
      <dc:creator>Malathi13</dc:creator>
      <dc:date>2017-05-01T17:42:34Z</dc:date>
    </item>
  </channel>
</rss>

