<?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: Data Difference Proportion in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Data-Difference-Proportion/m-p/824101#M325416</link>
    <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure to understand all the words you use, but I will try to answer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[Question 1]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to get rid of people who are in both work.Exp and work.Test, you add to your proc sql the condition [where E.Subject_ID=. or T.Subject_ID=.] :&lt;/P&gt;&lt;PRE&gt;Proc SQL;
Create Table Merge2 AS
Select
E.Exp_Date,E.Case_ID,E.Exposure,
coalesce(E.Subject_ID, T.Subject_ID) as Subject_ID,
T.Test_Date
from exp E FULL JOIN test T on (E.Subject_ID = T.Subject_ID)
where E.Subject_ID=. or T.Subject_ID=.;
quit;&lt;/PRE&gt;&lt;P&gt;if you want the opposite, to keep only subject who are in both table, you shall do an inner join instead of a full join :&lt;/P&gt;&lt;PRE&gt;Proc SQL;
Create Table Merge3 AS
Select
E.Exp_Date,E.Case_ID,E.Exposure,
coalesce(E.Subject_ID, T.Subject_ID) as Subject_ID,
T.Test_Date
from exp E INNER JOIN test T on (E.Subject_ID = T.Subject_ID);
quit;&lt;/PRE&gt;&lt;P&gt;Or left join for only subjects in table work.Exp or rigth join for only subjects in table work.Test.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[Question 2]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this the proportion you want ?&lt;/P&gt;&lt;PRE&gt;Proc SQL;
Create Table proportion AS
Select
mean(((days_diff&amp;gt;=5)*(days_diff&amp;lt;=10))) as proportion_in_5_to_10_days
from HW;
quit;&lt;/PRE&gt;&lt;P&gt;[Question 3]&lt;/P&gt;&lt;P&gt;There are different approachs to do this. "Better" approach depends on your point of view.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Axel Renoux&lt;/P&gt;</description>
    <pubDate>Tue, 19 Jul 2022 12:03:48 GMT</pubDate>
    <dc:creator>Renoux</dc:creator>
    <dc:date>2022-07-19T12:03:48Z</dc:date>
    <item>
      <title>Data Difference Proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Difference-Proportion/m-p/824024#M325400</link>
      <description>&lt;P&gt;I have 2 data sets (below are partial datasets) for persons that are exposed to an "xyz" disease and want to find the proportion of those who were tested within 5-10 days from there exposure:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Exp;&lt;BR /&gt;input Subject_ID Exp_Date : mmddyy10. Name $14-22 Case_ID Exposure $;&lt;BR /&gt;format exp_date date9.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 12/20/2019 Joe Smith 122 Home&lt;BR /&gt;1 09/30/2019 Joe Smith 435 Home&lt;BR /&gt;2 01/05/2020 Mary Mill 432 Work&lt;BR /&gt;3 11/04/2019 John Doe 129 Work&lt;BR /&gt;3 11/04/2019 John Doe 655 School&lt;BR /&gt;3 01/25/2020 John Doe 721 Work&lt;BR /&gt;;;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Test;&lt;BR /&gt;input Subject_ID Test_Date : mmddyy10. Name $14-23;&lt;BR /&gt;format test_date date9.;&lt;BR /&gt;datalines;&lt;BR /&gt;1 12/29/2019 Joe Smith&lt;BR /&gt;2 09/30/2019 Mary Mill&lt;BR /&gt;2 01/07/2020 Mary Mill&lt;BR /&gt;8 06/30/2019 Mark Roger&lt;BR /&gt;8 07/15/2019 Mark Roger&lt;BR /&gt;8 08/29/2019 Mark Roger&lt;BR /&gt;8 12/03/2019 Mark Roger&lt;BR /&gt;;;;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I've done:&lt;/P&gt;&lt;P&gt;I merged the 2 datasets using the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc SQL;&lt;BR /&gt;Create Table Merge AS&lt;BR /&gt;Select&lt;BR /&gt;E.Exp_Date,E.Case_ID,E.Exposure,&lt;BR /&gt;coalesce(E.Subject_ID, T.Subject_ID) as Subject_ID,&lt;BR /&gt;T.Test_Date&lt;BR /&gt;from exp E FULL JOIN test T on (E.Subject_ID = T.Subject_ID);&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then I found the date difference between exposure and test dates:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data HW;&lt;BR /&gt;set merge;&lt;BR /&gt;days_diff = intck('day', exp_date, test_date);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The result was as below. It shows an issue that the dates were filled in for matched persons such as Joe Smith and Mary Mill:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mayasak_1-1658206023186.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/73457i7AE09FD767F5406C/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mayasak_1-1658206023186.png" alt="mayasak_1-1658206023186.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;My questions are:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;How to get rid of the dates filled for the matched data.&lt;/LI&gt;&lt;LI&gt;How to get the proportion of those tested in the 5-10 days difference window. -Specifically the numerator and denominator.&lt;/LI&gt;&lt;LI&gt;Is there a better approach for getting the proportion?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 04:52:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Difference-Proportion/m-p/824024#M325400</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2022-07-19T04:52:51Z</dc:date>
    </item>
    <item>
      <title>Re: Data Difference Proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Difference-Proportion/m-p/824101#M325416</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure to understand all the words you use, but I will try to answer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[Question 1]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you want to get rid of people who are in both work.Exp and work.Test, you add to your proc sql the condition [where E.Subject_ID=. or T.Subject_ID=.] :&lt;/P&gt;&lt;PRE&gt;Proc SQL;
Create Table Merge2 AS
Select
E.Exp_Date,E.Case_ID,E.Exposure,
coalesce(E.Subject_ID, T.Subject_ID) as Subject_ID,
T.Test_Date
from exp E FULL JOIN test T on (E.Subject_ID = T.Subject_ID)
where E.Subject_ID=. or T.Subject_ID=.;
quit;&lt;/PRE&gt;&lt;P&gt;if you want the opposite, to keep only subject who are in both table, you shall do an inner join instead of a full join :&lt;/P&gt;&lt;PRE&gt;Proc SQL;
Create Table Merge3 AS
Select
E.Exp_Date,E.Case_ID,E.Exposure,
coalesce(E.Subject_ID, T.Subject_ID) as Subject_ID,
T.Test_Date
from exp E INNER JOIN test T on (E.Subject_ID = T.Subject_ID);
quit;&lt;/PRE&gt;&lt;P&gt;Or left join for only subjects in table work.Exp or rigth join for only subjects in table work.Test.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;[Question 2]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is this the proportion you want ?&lt;/P&gt;&lt;PRE&gt;Proc SQL;
Create Table proportion AS
Select
mean(((days_diff&amp;gt;=5)*(days_diff&amp;lt;=10))) as proportion_in_5_to_10_days
from HW;
quit;&lt;/PRE&gt;&lt;P&gt;[Question 3]&lt;/P&gt;&lt;P&gt;There are different approachs to do this. "Better" approach depends on your point of view.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Axel Renoux&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 12:03:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Difference-Proportion/m-p/824101#M325416</guid>
      <dc:creator>Renoux</dc:creator>
      <dc:date>2022-07-19T12:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: Data Difference Proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Difference-Proportion/m-p/824166#M325446</link>
      <description>&lt;P&gt;Thank you Axel,&lt;/P&gt;&lt;P&gt;For question 1, sorry for not being clear. What happened is:&lt;/P&gt;&lt;P&gt;Joe smith had exp_date from table one as 20DEC2019 and 30SEP2019 and only one test_date&amp;nbsp;from table two as 29DEC2019. When I did the merge, there were two test_date for this person, both 29DEC2019 so he had two date_diff 9 and 90, and 90 is not a true date_diff.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mary Mill, on the other hand, had only one exp_date and two tests, but after the merge, she had 2 exp_date and diff_date 2 and -97.&lt;/P&gt;&lt;P&gt;What I needed is to have only the 9 and 2 diff_date.&lt;/P&gt;&lt;P&gt;One thought I have is to deduplicate the data only when there's no corresponding test_date for the exp_date and vice versa but I have no clue ob how to do it.&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 14:58:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Difference-Proportion/m-p/824166#M325446</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2022-07-19T14:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Data Difference Proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Difference-Proportion/m-p/824171#M325450</link>
      <description>&lt;P&gt;To answer, I would need to know what information you would like in the following fictional case :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data Exp;
input Subject_ID Exp_Date : mmddyy10. Name $14-22 Case_ID Exposure $;
format exp_date date9.;
datalines;
9 12/20/2019 Mike Avery 122 Home
9 09/30/2019 Mike Avery 435 Home
;;;
run;

data Test;
input Subject_ID Test_Date : mmddyy10. Name $14-23;
format test_date date9.;
datalines;
9 10/29/2019 Mike Avery
9 01/07/2020 Mike Avery
;;;;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Matching &lt;U&gt;only&lt;/U&gt; (exp 12/20/2019) with (test 01/07/2020)? Or matching &lt;U&gt;also&lt;/U&gt;&amp;nbsp;(exp 09/30/2019) with (test 10/29/2019)? Or matching none of those two?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 15:25:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Difference-Proportion/m-p/824171#M325450</guid>
      <dc:creator>Renoux</dc:creator>
      <dc:date>2022-07-19T15:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: Data Difference Proportion</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Data-Difference-Proportion/m-p/824188#M325455</link>
      <description>&lt;P&gt;In your factual example, we should match both because each time the person was exposed, he/she had a corresponding test after this exposure. But if a person had exposure with no corresponding test such as below, only 09/30/2019 and 10/29/2019 should be matched:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data Exp;
input Subject_ID Exp_Date : mmddyy10. Name $14-22 Case_ID Exposure $;
format exp_date date9.;
datalines;
9 12/20/2019 Mike Avery 122 Home
9 09/30/2019 Mike Avery 435 Home
;;;
run;

data Test;
input Subject_ID Test_Date : mmddyy10. Name $14-23;
format test_date date9.;
datalines;
9 10/29/2019 Mike Avery
;;;;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;The same thing for those who had one exposure and two tests such as below, only 09/30/2019 and 10/29/2019 should be matched:&lt;/P&gt;&lt;PRE&gt;data Exp;
input Subject_ID Exp_Date : mmddyy10. Name $14-22 Case_ID Exposure $;
format exp_date date9.;
datalines;
9 09/30/2019 Mike Avery 435 Home
;;;
run;

data Test;
input Subject_ID Test_Date : mmddyy10. Name $14-23;
format test_date date9.;
datalines;
9 10/29/2019 Mike Avery
9 01/07/2020 Mike Avery
;;;;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jul 2022 16:12:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Data-Difference-Proportion/m-p/824188#M325455</guid>
      <dc:creator>mayasak</dc:creator>
      <dc:date>2022-07-19T16:12:07Z</dc:date>
    </item>
  </channel>
</rss>

