<?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 how to find  duplicated observations  by  amount in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-duplicated-observations-by-amount/m-p/32420#M6264</link>
    <description>Hi, Pros:&lt;BR /&gt;
&lt;BR /&gt;
Here is my senario:&lt;BR /&gt;
&lt;BR /&gt;
Data structure as follows:&lt;BR /&gt;
*******************************************&lt;BR /&gt;
id   date         service        type  amt &lt;BR /&gt;
1  12/1/2009    station1       A     +5&lt;BR /&gt;
1  12/1/2009    station1       A     +15&lt;BR /&gt;
1  12/1/2009    station1       A      -15&lt;BR /&gt;
&lt;BR /&gt;
2  12/1/2009    station1       B     +5&lt;BR /&gt;
2  12/1/2009    station1       B      -5&lt;BR /&gt;
2  12/1/2009    station1       B      +25&lt;BR /&gt;
2  12/1/2009    station1       B      -25&lt;BR /&gt;
2  12/1/2009    station1       B      20&lt;BR /&gt;
*****************************************&lt;BR /&gt;
&lt;BR /&gt;
Identify unique observation by sort by id date service type;&lt;BR /&gt;
&lt;BR /&gt;
The following result is expected. Many thanks. Tulip&lt;BR /&gt;
***************************************&lt;BR /&gt;
id   date         service        type  amt &lt;BR /&gt;
1  12/1/2009    station1       A     +5&lt;BR /&gt;
2  12/1/2009    station1       B      20&lt;BR /&gt;
***************************************</description>
    <pubDate>Fri, 18 Dec 2009 00:32:30 GMT</pubDate>
    <dc:creator>tulip</dc:creator>
    <dc:date>2009-12-18T00:32:30Z</dc:date>
    <item>
      <title>how to find  duplicated observations  by  amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-duplicated-observations-by-amount/m-p/32420#M6264</link>
      <description>Hi, Pros:&lt;BR /&gt;
&lt;BR /&gt;
Here is my senario:&lt;BR /&gt;
&lt;BR /&gt;
Data structure as follows:&lt;BR /&gt;
*******************************************&lt;BR /&gt;
id   date         service        type  amt &lt;BR /&gt;
1  12/1/2009    station1       A     +5&lt;BR /&gt;
1  12/1/2009    station1       A     +15&lt;BR /&gt;
1  12/1/2009    station1       A      -15&lt;BR /&gt;
&lt;BR /&gt;
2  12/1/2009    station1       B     +5&lt;BR /&gt;
2  12/1/2009    station1       B      -5&lt;BR /&gt;
2  12/1/2009    station1       B      +25&lt;BR /&gt;
2  12/1/2009    station1       B      -25&lt;BR /&gt;
2  12/1/2009    station1       B      20&lt;BR /&gt;
*****************************************&lt;BR /&gt;
&lt;BR /&gt;
Identify unique observation by sort by id date service type;&lt;BR /&gt;
&lt;BR /&gt;
The following result is expected. Many thanks. Tulip&lt;BR /&gt;
***************************************&lt;BR /&gt;
id   date         service        type  amt &lt;BR /&gt;
1  12/1/2009    station1       A     +5&lt;BR /&gt;
2  12/1/2009    station1       B      20&lt;BR /&gt;
***************************************</description>
      <pubDate>Fri, 18 Dec 2009 00:32:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-duplicated-observations-by-amount/m-p/32420#M6264</guid>
      <dc:creator>tulip</dc:creator>
      <dc:date>2009-12-18T00:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: how to find  duplicated observations  by  amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-duplicated-observations-by-amount/m-p/32421#M6265</link>
      <description>Please provide specific expectation so one will not make their own interpretation.  Specifically, I see where you chose the "first" occurence of variables "id date service type" with the first grouping but you chose the "last" occurences of the 2nd group.&lt;BR /&gt;
&lt;BR /&gt;
For this objective, regardless, you should explore using PROC SORT and a DATA step approach using a BY statement and IF FIRST.&lt;BREAK_VARIABLE&gt;  and/or IF LAST.&lt;BREAK_VARIABLE&gt;  to perform your data selection.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search argument for related DOC:&lt;BR /&gt;
&lt;BR /&gt;
data step by group processing site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/BREAK_VARIABLE&gt;&lt;/BREAK_VARIABLE&gt;</description>
      <pubDate>Fri, 18 Dec 2009 03:38:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-duplicated-observations-by-amount/m-p/32421#M6265</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-12-18T03:38:17Z</dc:date>
    </item>
    <item>
      <title>Re: how to find  duplicated observations  by  amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-duplicated-observations-by-amount/m-p/32422#M6266</link>
      <description>Hi tulip&lt;BR /&gt;
&lt;BR /&gt;
I'm not sure if I understand the problem exactly, however this code perform expected results.&lt;BR /&gt;
&lt;BR /&gt;
DATA station;&lt;BR /&gt;
 INPUT id  date:$10. service  $ type $ amt;&lt;BR /&gt;
CARDS;&lt;BR /&gt;
1 12/1/2009 station1 A +5&lt;BR /&gt;
1 12/1/2009 station1 A +15&lt;BR /&gt;
1 12/1/2009 station1 A -15&lt;BR /&gt;
2 12/1/2009 station1 B +5&lt;BR /&gt;
2 12/1/2009 station1 B -5&lt;BR /&gt;
2 12/1/2009 station1 B +25&lt;BR /&gt;
2 12/1/2009 station1 B -25&lt;BR /&gt;
2 12/1/2009 station1 B 20 &lt;BR /&gt;
;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
 select id, date, service, type, amt&lt;BR /&gt;
 from station&lt;BR /&gt;
 group by id, date, service, type, abs(amt)&lt;BR /&gt;
 having count(*) &amp;lt; 2&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
best regards&lt;BR /&gt;
&lt;BR /&gt;
Tomaž</description>
      <pubDate>Fri, 18 Dec 2009 07:19:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-duplicated-observations-by-amount/m-p/32422#M6266</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-12-18T07:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: how to find  duplicated observations  by  amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-duplicated-observations-by-amount/m-p/32423#M6267</link>
      <description>Hi, guys:&lt;BR /&gt;
&lt;BR /&gt;
It is so nice of you. I appreciate your help very much.&lt;BR /&gt;
&lt;BR /&gt;
The issue in this case can not be taken care of by using sort and by first....&lt;BR /&gt;
&lt;BR /&gt;
The final  observation needs to contain the correct amount.  &lt;BR /&gt;
&lt;BR /&gt;
Thanks Tom. Could you please try again the following case please?&lt;BR /&gt;
&lt;BR /&gt;
DATA station;&lt;BR /&gt;
INPUT id date:$10. service $ type $ amt;&lt;BR /&gt;
CARDS;&lt;BR /&gt;
1 12/1/2009 station1 A +5&lt;BR /&gt;
1 12/1/2009 station1 A +15&lt;BR /&gt;
1 12/1/2009 station1 A -15&lt;BR /&gt;
&lt;BR /&gt;
2 12/1/2009 station1 B +5&lt;BR /&gt;
2 12/1/2009 station1 B -5&lt;BR /&gt;
&lt;BR /&gt;
2 12/1/2009 station1 B 20 &lt;BR /&gt;
2 12/1/2009 station1 B +25&lt;BR /&gt;
2 12/1/2009 station1 B -25&lt;BR /&gt;
&lt;BR /&gt;
3 12/1/2009 station1 B +55&lt;BR /&gt;
3 12/1/2009 station1 B -55&lt;BR /&gt;
3 12/1/2009 station1 B 55&lt;BR /&gt;
;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
select id, date, service, type, amt&lt;BR /&gt;
from station&lt;BR /&gt;
group by id, date, service, type, abs(amt)&lt;BR /&gt;
having count(*) &amp;lt; 2&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
final expects the following. &lt;BR /&gt;
1 12/1/2009 station1 A +5&lt;BR /&gt;
&lt;BR /&gt;
2 12/1/2009 station1 B 20 &lt;BR /&gt;
&lt;BR /&gt;
3 12/1/2009 station1 B 55

Message was edited by: tulip</description>
      <pubDate>Fri, 18 Dec 2009 15:52:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-duplicated-observations-by-amount/m-p/32423#M6267</guid>
      <dc:creator>tulip</dc:creator>
      <dc:date>2009-12-18T15:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: how to find  duplicated observations  by  amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-duplicated-observations-by-amount/m-p/32424#M6268</link>
      <description>Hi, Tomaz:&lt;BR /&gt;
&lt;BR /&gt;
Could you please try again the following case additionally please?&lt;BR /&gt;
there is length limit so I do not show all.&lt;BR /&gt;
DATA station;&lt;BR /&gt;
INPUT id date:$10. service $ type $ amt;&lt;BR /&gt;
CARDS;&lt;BR /&gt;
3 12/1/2009 station1 B +55&lt;BR /&gt;
3 12/1/2009 station1 B -55&lt;BR /&gt;
3 12/1/2009 station1 B 55&lt;BR /&gt;
;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
select id, date, service, type, amt&lt;BR /&gt;
from station&lt;BR /&gt;
group by id, date, service, type, abs(amt)&lt;BR /&gt;
having count(*) &amp;lt; 2&lt;BR /&gt;
;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
final expects the following. &lt;BR /&gt;
1 12/1/2009 station1 A +5&lt;BR /&gt;
&lt;BR /&gt;
2 12/1/2009 station1 B 20 &lt;BR /&gt;
&lt;BR /&gt;
3 12/1/2009 station1 B 55</description>
      <pubDate>Fri, 18 Dec 2009 16:02:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-duplicated-observations-by-amount/m-p/32424#M6268</guid>
      <dc:creator>tulip</dc:creator>
      <dc:date>2009-12-18T16:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: how to find  duplicated observations  by  amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-duplicated-observations-by-amount/m-p/32425#M6269</link>
      <description>final show is 3 12/1/2009 station1 B +55</description>
      <pubDate>Fri, 18 Dec 2009 16:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-duplicated-observations-by-amount/m-p/32425#M6269</guid>
      <dc:creator>tulip</dc:creator>
      <dc:date>2009-12-18T16:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: how to find  duplicated observations  by  amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-duplicated-observations-by-amount/m-p/32426#M6270</link>
      <description>I see&lt;BR /&gt;
maybe using sum instead abs  is more appropriate.&lt;BR /&gt;
&lt;BR /&gt;
Tomaž</description>
      <pubDate>Mon, 21 Dec 2009 07:36:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-duplicated-observations-by-amount/m-p/32426#M6270</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-12-21T07:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to find  duplicated observations  by  amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-duplicated-observations-by-amount/m-p/32427#M6271</link>
      <description>Belated thanks, Tomaz. Further help is needed.&lt;BR /&gt;
&lt;BR /&gt;
when I replace abs to sum function. Error message came up. Please advise. Thanks.&lt;BR /&gt;
&lt;BR /&gt;
DATA station;&lt;BR /&gt;
INPUT id date:$10. service $ type $ amt;&lt;BR /&gt;
CARDS;&lt;BR /&gt;
3 12/1/2009 station1 B +55&lt;BR /&gt;
3 12/1/2009 station1 B -55&lt;BR /&gt;
3 12/1/2009 station1 B +55&lt;BR /&gt;
;&lt;BR /&gt;
RUN;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
select id, date, service, type, amt&lt;BR /&gt;
from station&lt;BR /&gt;
group by id, date, service, type, abs(amt)&lt;BR /&gt;
having count(*) &amp;lt; 2 ;&lt;BR /&gt;
;&lt;BR /&gt;
quit;

Message was edited by: tulip</description>
      <pubDate>Sat, 23 Jan 2010 15:26:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-duplicated-observations-by-amount/m-p/32427#M6271</guid>
      <dc:creator>tulip</dc:creator>
      <dc:date>2010-01-23T15:26:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to find  duplicated observations  by  amount</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-find-duplicated-observations-by-amount/m-p/32428#M6272</link>
      <description>As I stated previously, you can use IF LAST.&lt;BREAK_VARIABLE&gt; THEN OUTPUT;  with a sorted file using a BY statement and &lt;BREAK_VARIABLE&gt; being the last variable in the BY.  From your explanation, I believe the BY variables are ID, DATE (suggest inputting as a SAS NUMERIC date, not character), SERVICE and TYPE.  Use EQUALS on the SORT to ensure the incoming order is maintained for your AMT values.&lt;BR /&gt;
&lt;BR /&gt;
Again, see the recommended SAS support site DOC references for details, and also the EQUALS parameter discussion for PROC SORT.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/BREAK_VARIABLE&gt;&lt;/BREAK_VARIABLE&gt;</description>
      <pubDate>Sat, 23 Jan 2010 16:59:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-find-duplicated-observations-by-amount/m-p/32428#M6272</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-01-23T16:59:07Z</dc:date>
    </item>
  </channel>
</rss>

