<?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: dealing with duplicate records in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-duplicate-records/m-p/52647#M14493</link>
    <description>You might be able to do what you want with something like:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
  infile cards delimiter="@";&lt;BR /&gt;
  informat class $10.;&lt;BR /&gt;
  format date date9.;&lt;BR /&gt;
  input ID $ semester $ class credits grade_recieved $;&lt;BR /&gt;
  date=mdy(substr(semester,1,1),1,substr(semester,2,2));&lt;BR /&gt;
  cards;&lt;BR /&gt;
04F1M@191@C S 131@2.0@UW&lt;BR /&gt;
04F1M@187 @CL CV 241@3.0@C &lt;BR /&gt;
04F1M@587@ECON 110@3.0@D- &lt;BR /&gt;
04F1M@590@ECON 110@3.0@B &lt;BR /&gt;
04F1M@586@ENGL 115@4.0@B &lt;BR /&gt;
04F1M@590@ENGL 391@3.0@C-&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=have;&lt;BR /&gt;
  by ID class date;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want;&lt;BR /&gt;
  set have;&lt;BR /&gt;
  by id class;&lt;BR /&gt;
  if first.class then count=1;&lt;BR /&gt;
  else count+1;&lt;BR /&gt;
  if last.class then output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
HTH,&lt;BR /&gt;
Art</description>
    <pubDate>Mon, 18 Apr 2011 20:48:11 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2011-04-18T20:48:11Z</dc:date>
    <item>
      <title>dealing with duplicate records</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-duplicate-records/m-p/52646#M14492</link>
      <description>I have data containing student IDs, classes, grades, semesters, etc. I want to find all the times that a student repeated a class; so the same student ID and the same course number but not necessarily the same grade or semester. i want to keep only the last (by date) recorded grade for that class but at the same time i want to count the number of repeat classes.&lt;BR /&gt;
here is some data:&lt;BR /&gt;
&lt;BR /&gt;
ID@semester(1st number=semester number/last 2 numbers=year)&lt;BR /&gt;
                     @class@credits@grade recieved&lt;BR /&gt;
 &lt;BR /&gt;
04F1M@191@C S      131@2.0@UW@ &lt;BR /&gt;
04F1M@187 @CL CV 241@3.0@C@  &lt;BR /&gt;
04F1M@587@ECON  110@3.0@D-@ &lt;BR /&gt;
04F1M@590@ECON  110@3.0@B@ &lt;BR /&gt;
04F1M@586@ENGL  115@4.0@B@   &lt;BR /&gt;
04F1M@590@ENGL  391@3.0@C-@ &lt;BR /&gt;
&lt;BR /&gt;
thanks</description>
      <pubDate>Mon, 18 Apr 2011 20:06:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dealing-with-duplicate-records/m-p/52646#M14492</guid>
      <dc:creator>PCrider</dc:creator>
      <dc:date>2011-04-18T20:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: dealing with duplicate records</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-duplicate-records/m-p/52647#M14493</link>
      <description>You might be able to do what you want with something like:&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
  infile cards delimiter="@";&lt;BR /&gt;
  informat class $10.;&lt;BR /&gt;
  format date date9.;&lt;BR /&gt;
  input ID $ semester $ class credits grade_recieved $;&lt;BR /&gt;
  date=mdy(substr(semester,1,1),1,substr(semester,2,2));&lt;BR /&gt;
  cards;&lt;BR /&gt;
04F1M@191@C S 131@2.0@UW&lt;BR /&gt;
04F1M@187 @CL CV 241@3.0@C &lt;BR /&gt;
04F1M@587@ECON 110@3.0@D- &lt;BR /&gt;
04F1M@590@ECON 110@3.0@B &lt;BR /&gt;
04F1M@586@ENGL 115@4.0@B &lt;BR /&gt;
04F1M@590@ENGL 391@3.0@C-&lt;BR /&gt;
;&lt;BR /&gt;
&lt;BR /&gt;
proc sort data=have;&lt;BR /&gt;
  by ID class date;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want;&lt;BR /&gt;
  set have;&lt;BR /&gt;
  by id class;&lt;BR /&gt;
  if first.class then count=1;&lt;BR /&gt;
  else count+1;&lt;BR /&gt;
  if last.class then output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
HTH,&lt;BR /&gt;
Art</description>
      <pubDate>Mon, 18 Apr 2011 20:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dealing-with-duplicate-records/m-p/52647#M14493</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-04-18T20:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: dealing with duplicate records</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/dealing-with-duplicate-records/m-p/52648#M14494</link>
      <description>How about:&lt;BR /&gt;
&lt;BR /&gt;
data Classes_Taken;&lt;BR /&gt;
infile cards delimiter="@";&lt;BR /&gt;
informat class $10.;&lt;BR /&gt;
format date date9.;&lt;BR /&gt;
input ID $ semester $ class credits grade_recieved $;&lt;BR /&gt;
class_date=mdy(substr(semester,1,1),1,substr(semester,2,2));&lt;BR /&gt;
cards;&lt;BR /&gt;
04F1M@191@C S 131@2.0@UW&lt;BR /&gt;
04F1M@187 @CL CV 241@3.0@C &lt;BR /&gt;
04F1M@587@ECON 110@3.0@D- &lt;BR /&gt;
04F1M@590@ECON 110@3.0@B &lt;BR /&gt;
04F1M@586@ENGL 115@4.0@B &lt;BR /&gt;
04F1M@590@ENGL 391@3.0@C-&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table retakes as&lt;BR /&gt;
select&lt;BR /&gt;
id,&lt;BR /&gt;
class,&lt;BR /&gt;
count(*) as times_taken,&lt;BR /&gt;
max(class_date) Last_date&lt;BR /&gt;
from work.classes_taken&lt;BR /&gt;
group by id, class&lt;BR /&gt;
having count(*)&amp;gt;1;&lt;BR /&gt;
&lt;BR /&gt;
create table last_retake as&lt;BR /&gt;
select&lt;BR /&gt;
t2.*,&lt;BR /&gt;
t1.times_taken&lt;BR /&gt;
from work.retakes t1 inner join work.classes_taken t2&lt;BR /&gt;
on t1.id=t2.id and t1.class=t2.class and t1.last_date=t2.class_date;&lt;BR /&gt;
quit;</description>
      <pubDate>Mon, 18 Apr 2011 21:14:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/dealing-with-duplicate-records/m-p/52648#M14494</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2011-04-18T21:14:21Z</dc:date>
    </item>
  </channel>
</rss>

