<?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 output duplicate date and time across all visits? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-duplicate-date-and-time-across-all-visits/m-p/871831#M344448</link>
    <description>&lt;P&gt;Of course, if you have more than 2 visits on the same time, you will still get too many combinations. In that case, it may be simpler with a datastep, e.g.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=visits;
  by patient_id visit_time;
run;

data duplicates;
  set visits;
  by patient_id visit_time;
  if not(first.visit_time and last.visit_time);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 25 Apr 2023 11:28:09 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2023-04-25T11:28:09Z</dc:date>
    <item>
      <title>How to output duplicate date and time across all visits?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-duplicate-date-and-time-across-all-visits/m-p/871786#M344444</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Kindly help as this is very urgent.&lt;BR /&gt;&lt;BR /&gt;There are two fields to be considered, date and time. If they are both duplicates across any 2 visits in a subject, then it must fire in the final output.&lt;BR /&gt;&lt;BR /&gt;The issue here is, I tried self join but many to many join is occurring. For instance, for subject 101, Screening visit from table 1 (date = 30Jan2020 and time=11:15) is getting matched with Day 1 visit from table 2 (date = 30Jan2020 and time=11:15) which is the 1st row in the final output, but I'm also getting another 2nd row where Day 1 visit from table 1 (date = 30Jan2020 and time=11:15) is getting matched with Screening visit from table 2 (date = 30Jan2020 and time=11:15) . I'm expecting just one record whereas I'm getting vice versa scenarios, how do I avoid the vice versa scenario here and get just 1 record in the output?&lt;BR /&gt;&lt;BR /&gt;Thanks in advance. Kindly help.</description>
      <pubDate>Tue, 25 Apr 2023 07:47:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-duplicate-date-and-time-across-all-visits/m-p/871786#M344444</guid>
      <dc:creator>vidya3</dc:creator>
      <dc:date>2023-04-25T07:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to output duplicate date and time across all visits?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-duplicate-date-and-time-across-all-visits/m-p/871790#M344445</link>
      <description>&lt;P&gt;Please post sample data. Makes it much easier to provide a usable code answer.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 08:10:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-duplicate-date-and-time-across-all-visits/m-p/871790#M344445</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2023-04-25T08:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to output duplicate date and time across all visits?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-duplicate-date-and-time-across-all-visits/m-p/871828#M344446</link>
      <description>&lt;P&gt;If it is a self join, I assume you are joining on something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;a.patient_id=b.patient_id and
a.visit_time = b.visit_time and 
a.visit_text ne b.visit_text&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you do not want the output both ways, just put change the "not equal" to "greater than" or "smaller than", e.g.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;a.patient_id=b.patient_id and
a.visit_time = b.visit_time and 
a.visit_text &amp;lt; b.visit_text&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 11:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-duplicate-date-and-time-across-all-visits/m-p/871828#M344446</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-04-25T11:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to output duplicate date and time across all visits?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-duplicate-date-and-time-across-all-visits/m-p/871831#M344448</link>
      <description>&lt;P&gt;Of course, if you have more than 2 visits on the same time, you will still get too many combinations. In that case, it may be simpler with a datastep, e.g.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=visits;
  by patient_id visit_time;
run;

data duplicates;
  set visits;
  by patient_id visit_time;
  if not(first.visit_time and last.visit_time);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Apr 2023 11:28:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-duplicate-date-and-time-across-all-visits/m-p/871831#M344448</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2023-04-25T11:28:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to output duplicate date and time across all visits?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-duplicate-date-and-time-across-all-visits/m-p/871841#M344451</link>
      <description>&lt;P&gt;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;recommends please provide samples of both input datasets (table1 and table2), a sample of what you want in your output dataset based on the inputs, and the SAS code you have currently.&lt;BR /&gt;&lt;BR /&gt;For example:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create sample Table 1 data */
data work.table1 ;
	format 
		date1 date7. 
		time1 time5. ;
	infile cards ;
	input 
		subject1      $3.
		date1    : date7.
		time1    : time5. ;
	output 
		work.table1 ;
cards ;
101 30Jan20 11:15
201 31Jan20 10:15
;

/* Create sample Table 2 data */
data work.table2 ;
	format 
		date2 date7. 
		time2 time5. ;
	infile cards ;
	input 
		subject2      $3.
		date2    : date7.
		time2    : time5. ;
	output 
		work.table2 ;
cards ;
101 30Jan20 11:15
101 30Jan20 11:15
201 31Jan20 10:15
201 01Feb20 10:15
;

/* Create sample want data                        */
/* This is the resulting dataset I want           */
/* Based on the input datasets table1 and table 2 */
data work.want ;
	format 
		date date7. 
		time time5. ;
	infile cards ;
	input 
		subject      $3.
		date    : date7.
		time    : time5. ;
	output 
		work.want ;
cards ;
101 30Jan20 11:15
201 31Jan20 10:15
201 01Feb20 10:15
;

/* My code to generate the want dataset from the input datasets table1 and table2 */
proc sql ;
	create table 
		work.joined as
	select 
		table1.*,
		table2.*
	from
		table1, 
		table2 
	where
		table1.subject1=table2.subject2 and 
		table1.date1=table2.date2 and 
		table1.time1=table2.time2 
	;
		
quit ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Apr 2023 12:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-duplicate-date-and-time-across-all-visits/m-p/871841#M344451</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2023-04-25T12:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to output duplicate date and time across all visits?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-output-duplicate-date-and-time-across-all-visits/m-p/871867#M344458</link>
      <description>&lt;P&gt;You can use first.variable/last.variable to flag duplicate records. Depending on the VISIT values, you can consider sorting order (eg. subjectid date time descending visit)&lt;/P&gt;
&lt;P&gt;Eg:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input subjectid $ visit $ date:date9. time:time5.;
	format date date9. time time5.;
	cards;
101 Screen	30Jan2020 11:15
101 Day1 30Jan2020 11:15
101 Week6 15Mar2020 12:15
101 Week12 01May2020 12:00
;
proc print;run;

proc sort data=have;
	by subjectid date time descending visit;
run; 

data want;
	set have;
	by subjectid date time;
	length flag $20;
	if not first.time then flag= 'duplicate date';
proc print;run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 428px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83165i8C22A0D1219CA0D3/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 13:45:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-output-duplicate-date-and-time-across-all-visits/m-p/871867#M344458</guid>
      <dc:creator>A_Kh</dc:creator>
      <dc:date>2023-04-25T13:45:33Z</dc:date>
    </item>
  </channel>
</rss>

