<?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: keep only one record of the examination if the exam date is same for each ID. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/keep-only-one-record-of-the-examination-if-the-exam-date-is-same/m-p/888004#M350840</link>
    <description>&lt;P&gt;It is usually helpful to provide example of the data you have and the desired result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a guess as two what you may want:&lt;/P&gt;
&lt;PRE&gt;data data1;
   set data;
   by ID DATE exam;
   if exam="No" then output;
   else if exam="Yes" AND FIRST.EXAM then output;

run;&lt;/PRE&gt;
&lt;P&gt;Because you do not describe any rules for exam='No' the above will output ALL of the Exam='No' for a given date.&lt;/P&gt;
&lt;P&gt;If you only want at most one No and one Yes then perhaps:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data data1;
   set data;
   by ID DATE exam;
   if FIRST.EXAM ;

run;&lt;/PRE&gt;
&lt;P&gt;You don't describe what the actual role of DATE plays in this very well or exactly what the requirement is. If you only want one date per ID you really need to provide example data and the result so we have a chance of following the hopefully expanded description of what date's role in the output data may be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 05 Aug 2023 03:55:05 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-08-05T03:55:05Z</dc:date>
    <item>
      <title>keep only one record of the examination if the exam date is same for each ID.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-only-one-record-of-the-examination-if-the-exam-date-is-same/m-p/888002#M350838</link>
      <description>&lt;P&gt;If the patient took the exam (exam="Yes"), and if there are duplicate records with the same visit date, I would like to keep only one record, but it seems my code deletes more records. How to correct this code? I think this code only kept the first date for each ID, but for each ID, there are multiple dates. I'm not sure how to write the correct code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sort data=data;&lt;BR /&gt;by ID DATE exam;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data data1;&lt;BR /&gt;set data;&lt;BR /&gt;by ID DATE;&lt;BR /&gt;if exam="No" then output;&lt;BR /&gt;else if exam="Yes" then do;&lt;BR /&gt;if first.DATE then output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Aug 2023 03:31:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-only-one-record-of-the-examination-if-the-exam-date-is-same/m-p/888002#M350838</guid>
      <dc:creator>L777</dc:creator>
      <dc:date>2023-08-05T03:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: keep only one record of the examination if the exam date is same for each ID.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-only-one-record-of-the-examination-if-the-exam-date-is-same/m-p/888004#M350840</link>
      <description>&lt;P&gt;It is usually helpful to provide example of the data you have and the desired result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is a guess as two what you may want:&lt;/P&gt;
&lt;PRE&gt;data data1;
   set data;
   by ID DATE exam;
   if exam="No" then output;
   else if exam="Yes" AND FIRST.EXAM then output;

run;&lt;/PRE&gt;
&lt;P&gt;Because you do not describe any rules for exam='No' the above will output ALL of the Exam='No' for a given date.&lt;/P&gt;
&lt;P&gt;If you only want at most one No and one Yes then perhaps:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data data1;
   set data;
   by ID DATE exam;
   if FIRST.EXAM ;

run;&lt;/PRE&gt;
&lt;P&gt;You don't describe what the actual role of DATE plays in this very well or exactly what the requirement is. If you only want one date per ID you really need to provide example data and the result so we have a chance of following the hopefully expanded description of what date's role in the output data may be.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Aug 2023 03:55:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-only-one-record-of-the-examination-if-the-exam-date-is-same/m-p/888004#M350840</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-05T03:55:05Z</dc:date>
    </item>
    <item>
      <title>Re: keep only one record of the examination if the exam date is same for each ID.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-only-one-record-of-the-examination-if-the-exam-date-is-same/m-p/888039#M350864</link>
      <description>&lt;P&gt;Assuming EXAM only takes the values "No" or "Yes", then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=data;
  by ID DATE exam;
run;

data data1;
  set date;
  by id date exam;
  if exam='No' or first.exam=1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This gives you all the No's and just the first Yes for each ID/DATE.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Aug 2023 20:42:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-only-one-record-of-the-examination-if-the-exam-date-is-same/m-p/888039#M350864</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-08-05T20:42:31Z</dc:date>
    </item>
  </channel>
</rss>

