<?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 Differences between Observations By Group in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Differences-between-Observations-By-Group/m-p/722004#M27847</link>
    <description>&lt;P&gt;I am working with a matched case control study, where there are multiple controls (case = 0) matched to one case (case = 1) by the variable "trimgroupid".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each observation has it's own ID (uniqueid).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I want to do is identify the controls that have a date of birth (dob) &amp;gt; 1 year away (+ or -) from it's matched case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is what I have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines delimiter=',';
	length uniqueid $5 trimgroupid $7;
	format dob mmddyy10.;
	input uniqueid $ trimgroupid $ dob mmddyy10. case;
	datalines;
	X0131,XX01491,03/10/2000,1
	X1831,XX01491,12/05/2002,0
	X3691,XX01491,06/02/2000,0
	X1971,XX04997,02/05/2010,1
	X2611,XX04997,03/13/2011,0
	X4371,XX04997,06/25/2009,0
	X4621,XX04997,01/01/2009,0
	;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And here is what I want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	infile datalines delimiter=',';
	length uniqueid $5 trimgroupid $7;
	format dob mmddyy10.;
	input uniqueid $ trimgroupid $ dob mmddyy10. case;
	datalines;
	X1831,XX01491,12/05/2002,0
	X2611,XX04997,03/13/2011,0
	X4621,XX04997,01/01/2009,0
	;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the trimgroupid value of XX01491 there is 1 control whose dob is &amp;gt; 1 year away from the case it is matched to.&lt;/P&gt;
&lt;P&gt;For the trimgroupid value of XX04997 there are 2 controls whose dob is &amp;gt; 1 year away from the case it is matched to.&lt;/P&gt;</description>
    <pubDate>Thu, 25 Feb 2021 21:39:40 GMT</pubDate>
    <dc:creator>JJ_83</dc:creator>
    <dc:date>2021-02-25T21:39:40Z</dc:date>
    <item>
      <title>Differences between Observations By Group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Differences-between-Observations-By-Group/m-p/722004#M27847</link>
      <description>&lt;P&gt;I am working with a matched case control study, where there are multiple controls (case = 0) matched to one case (case = 1) by the variable "trimgroupid".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Each observation has it's own ID (uniqueid).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I want to do is identify the controls that have a date of birth (dob) &amp;gt; 1 year away (+ or -) from it's matched case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is what I have:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines delimiter=',';
	length uniqueid $5 trimgroupid $7;
	format dob mmddyy10.;
	input uniqueid $ trimgroupid $ dob mmddyy10. case;
	datalines;
	X0131,XX01491,03/10/2000,1
	X1831,XX01491,12/05/2002,0
	X3691,XX01491,06/02/2000,0
	X1971,XX04997,02/05/2010,1
	X2611,XX04997,03/13/2011,0
	X4371,XX04997,06/25/2009,0
	X4621,XX04997,01/01/2009,0
	;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And here is what I want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	infile datalines delimiter=',';
	length uniqueid $5 trimgroupid $7;
	format dob mmddyy10.;
	input uniqueid $ trimgroupid $ dob mmddyy10. case;
	datalines;
	X1831,XX01491,12/05/2002,0
	X2611,XX04997,03/13/2011,0
	X4621,XX04997,01/01/2009,0
	;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For the trimgroupid value of XX01491 there is 1 control whose dob is &amp;gt; 1 year away from the case it is matched to.&lt;/P&gt;
&lt;P&gt;For the trimgroupid value of XX04997 there are 2 controls whose dob is &amp;gt; 1 year away from the case it is matched to.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Feb 2021 21:39:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Differences-between-Observations-By-Group/m-p/722004#M27847</guid>
      <dc:creator>JJ_83</dc:creator>
      <dc:date>2021-02-25T21:39:40Z</dc:date>
    </item>
    <item>
      <title>Re: Differences between Observations By Group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Differences-between-Observations-By-Group/m-p/722023#M27848</link>
      <description>&lt;P&gt;To simplify the code I used 365 days as a year, neglecting a leap year:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	infile datalines delimiter=',';
	length uniqueid $5 trimgroupid $7;
	format dob mmddyy10.;
	input uniqueid $ trimgroupid $ dob mmddyy10. case;
	datalines;
	X0131,XX01491,03/10/2000,1
	X1831,XX01491,12/05/2002,0
	X3691,XX01491,06/02/2000,0
	X1971,XX04997,02/05/2010,1
	X2611,XX04997,03/13/2011,0
	X4371,XX04997,06/25/2009,0
	X4621,XX04997,01/01/2009,0
	;
run;
proc sort data=have; by trimgroupid dob; run;
data want;
 set have;
  by trimgroupid dob;
     if dif(dob) ge 365;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Feb 2021 01:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Differences-between-Observations-By-Group/m-p/722023#M27848</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-02-26T01:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: Differences between Observations By Group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Differences-between-Observations-By-Group/m-p/722040#M27850</link>
      <description>&lt;P&gt;If the data are already sorted by trimgroupid, then a MERGE statement (with a rename), accompanied by a BY statement will do what you want:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines delimiter=',';
  length uniqueid $5 trimgroupid $7;
  format dob mmddyy10.;
  input uniqueid $ trimgroupid $ dob mmddyy10. case;
datalines;
X0131,XX01491,03/10/2000,1
X1831,XX01491,12/05/2002,0
X3691,XX01491,06/02/2000,0
X1971,XX04997,02/05/2010,1
X2611,XX04997,03/13/2011,0
X4371,XX04997,06/25/2009,0
X4621,XX04997,01/01/2009,0
run;
data want;
  merge have (where=(case=1) rename=(dob=case_dob))
        have (where=(case=0));
  by trimgroupid;
  if intck('year',case_dob,dob,'continuous')&amp;gt;0 or 
     intck('year',dob,case_dob,'continuous')&amp;gt;0 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since the control dob's can be either before or after the matching case dob, the subsetting IF checks on the interval from &lt;EM&gt;&lt;STRONG&gt;case_dob to dob&lt;/STRONG&gt;&lt;/EM&gt;, and also from &lt;EM&gt;&lt;STRONG&gt;dob to case_dob&lt;/STRONG&gt;&lt;/EM&gt;.&amp;nbsp; &amp;nbsp;Note this relies on the presence of exactly one case per trimgroupid.&amp;nbsp; The program also has the advantage of storing the case_dob value in each of the qualifying controls.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2021 04:05:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Differences-between-Observations-By-Group/m-p/722040#M27850</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-02-26T04:05:37Z</dc:date>
    </item>
    <item>
      <title>Re: Differences between Observations By Group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Differences-between-Observations-By-Group/m-p/722249#M27885</link>
      <description>&lt;P&gt;This worked great, thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2021 20:27:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Differences-between-Observations-By-Group/m-p/722249#M27885</guid>
      <dc:creator>JJ_83</dc:creator>
      <dc:date>2021-02-26T20:27:58Z</dc:date>
    </item>
    <item>
      <title>Re: Differences between Observations By Group</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Differences-between-Observations-By-Group/m-p/722250#M27886</link>
      <description>&lt;P&gt;This solution also works, but for my particular dataset the other approach fit better.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2021 20:28:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Differences-between-Observations-By-Group/m-p/722250#M27886</guid>
      <dc:creator>JJ_83</dc:creator>
      <dc:date>2021-02-26T20:28:56Z</dc:date>
    </item>
  </channel>
</rss>

