<?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: Deleting Occurrences which do not make sense in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Deleting-Occurrences-which-do-not-make-sense/m-p/641195#M21821</link>
    <description>&lt;P&gt;First thing to do: convert the dates to sas-dates, so that sorting by date yields the expected results - also necessary to compare dates.&lt;/P&gt;</description>
    <pubDate>Mon, 20 Apr 2020 07:01:23 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2020-04-20T07:01:23Z</dc:date>
    <item>
      <title>Deleting Occurrences which do not make sense</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Deleting-Occurrences-which-do-not-make-sense/m-p/641191#M21819</link>
      <description>&lt;P&gt;Hello SAS community,&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;I have a dataset with 3 rows: ID, Date, Event. ID and Date are pretty self-explanatory but Event contains different education phases for each ID: Kindergarten, Preschool, Primary, High School and University. Now, the data is full of errors - sometimes the dates are wrong in which it is out of sequence or duplicated. Sometimes, it may show that the customer participated in say for example, high school&amp;nbsp;&lt;STRONG&gt;before&amp;nbsp;&lt;/STRONG&gt;primary school etc. (Gaps are completely fine - ie. Fine for a customer to have a date where he attended Kindergarten then very next line can be the date he went to University). My logic is to assume these are entries are completely erroneous.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;How can I logically sort this so that any data out-of-sequence which does not make sense is deleted? (If customer had a 'University' stint in between 'Primary' and 'High School' then delete this row)&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Data I have:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input id date event;&lt;/P&gt;&lt;P&gt;1 01012000 Kindergarten&lt;/P&gt;&lt;P&gt;1 01012001 High school&lt;/P&gt;&lt;P&gt;1 01012003 Primary&lt;/P&gt;&lt;P&gt;1 01012010 High School&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2 01012000 University&lt;/P&gt;&lt;P&gt;2 01012010 High School&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3 01012009 Kindergarten&lt;/P&gt;&lt;P&gt;3 01012010 Preschool&lt;/P&gt;&lt;P&gt;3 01012012 Kindergarten&lt;/P&gt;&lt;P&gt;3 01012019 High School&lt;/P&gt;&lt;P&gt;3 01012022 Kindergarten&lt;/P&gt;&lt;P&gt;3 01012024 University&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Data I want:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;input id date event;&lt;/P&gt;&lt;P&gt;1 01012000 Kindergarten&lt;/P&gt;&lt;P&gt;1 01012003 Primary&lt;/P&gt;&lt;P&gt;1 01012010 High School&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2 01012010 High School&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3 01012009 Kindergarten&lt;/P&gt;&lt;P&gt;3 01012010 Preschool&lt;/P&gt;&lt;P&gt;3 01012019 High School&lt;/P&gt;&lt;P&gt;3 01012024 University&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks for your kind help SAS community.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 06:19:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Deleting-Occurrences-which-do-not-make-sense/m-p/641191#M21819</guid>
      <dc:creator>Bounce</dc:creator>
      <dc:date>2020-04-20T06:19:02Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting Occurrences which do not make sense</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Deleting-Occurrences-which-do-not-make-sense/m-p/641193#M21820</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/267739"&gt;@Bounce&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello SAS community,&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;How can I logically sort this so that any data out-of-sequence which does not make sense is deleted? (If customer had a 'University' stint in between 'Primary' and 'High School' then delete this row)&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Data I have:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data have;&lt;/P&gt;
&lt;P&gt;input id date event;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2 01012000 University&lt;/P&gt;
&lt;P&gt;2 01012010 High School&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For ID 2 you have University followed by High School.&amp;nbsp; You could delete either one to meet your objective.&amp;nbsp; What rule are you using to choose which one to delete?&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 06:46:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Deleting-Occurrences-which-do-not-make-sense/m-p/641193#M21820</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-04-20T06:46:53Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting Occurrences which do not make sense</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Deleting-Occurrences-which-do-not-make-sense/m-p/641195#M21821</link>
      <description>&lt;P&gt;First thing to do: convert the dates to sas-dates, so that sorting by date yields the expected results - also necessary to compare dates.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Apr 2020 07:01:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Deleting-Occurrences-which-do-not-make-sense/m-p/641195#M21821</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-04-20T07:01:23Z</dc:date>
    </item>
    <item>
      <title>Re: Deleting Occurrences which do not make sense</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Deleting-Occurrences-which-do-not-make-sense/m-p/641220#M21824</link>
      <description>&lt;P&gt;Please try the below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id date:ddmmyy8.  event&amp;amp;:$20.;
format date date9.;
cards;
1 01012000 Kindergarten
1 01012001 High school
1 01012003 Primary
1 01012010 High School
2 01012000 University
2 01012010 High School
3 01012009 Kindergarten
3 01012010 Preschool
3 01012012 Kindergarten
3 01012019 High School
3 01012022 Kindergarten
3 01012024 University
;

proc format;
invalue sch
'Kindergarten'=1
'High school'=3
'High School'=3
'Primary'=2
'University'=4
'Preschool'=1
;

proc sort data=have;
by id date;
run;

data have;
set have;
schnum=input(event,sch.);
by id date;
run;

proc sort data=have;
by id schnum;
run;

data want;
set have;
by id schnum;
retain schnum2 date2;
if first.id then schnum2=schnum;
if first.id then date2=date;
format date2 date9.;
if schnum&amp;gt;schnum2 and date&amp;lt;date2 then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 20 Apr 2020 08:51:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Deleting-Occurrences-which-do-not-make-sense/m-p/641220#M21824</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-04-20T08:51:11Z</dc:date>
    </item>
  </channel>
</rss>

