<?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: Check matching criteria in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Check-matching-criteria/m-p/888630#M351083</link>
    <description>&lt;P&gt;If all CASEs precede the relevant CONTROL candidates, then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data match;
  input Id $  case_control $ match_caseid $ age gender $ dg_date : ddmmyy10. ;
  format dg_date ddmmyy10.;
datalines;
A1 Case    A1 20 F 20/08/2023
A2 Control A1 23 F 21/07/2023
A3 Control A1 22 F 22/09/2023
B1 Case    B1 30 M 1/06/2023
B2 Control B1 35 M 24/08/2023
B3 Control B1 33 M 12/06/2023
C1 Case    C1 40 M 26/05/2023
C2 Control C1 38 M 30/04/2023
D1 Case    D1 47 M 28/07/2023
D2 Control D1 41 M 29/06/2023
D3 Control D1 50 F 30/07/2023
D4 Control D1 63 M 31/07/2023
run;


data want (drop=_:);
  set match
      match (obs=0 rename=(age=_age gender=_gender dg_date=_dg_date));

  if _n_=1 then do;
    declare hash h();
      h.definekey('id');
      h.definedata('_age','_gender','_dg_date');
      h.definedone();
  end;
    
  if case_control='Case' then do;
    _age=age;
    _gender=gender;
    _dg_date=dg_date;
    h.add();
  end;
  else do;
    _rc=h.find(key:match_caseid);
    if _rc^=0 then Match='Match_Caseid Not Found';
    else if gender=_gender and abs(age-_age)&amp;lt;=3
        and dg_date &amp;gt;  intnx('month',_dg_date,-1,'sameday') 
        and dg_date &amp;lt;= intnx('month',_dg_date,+1,'sameday')
        then Match='Yes';
    else Match='No ';
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Edit: minor change made to the "&lt;EM&gt;&lt;STRONG&gt;else if .... then Match='Yes'&lt;/STRONG&gt;&lt;/EM&gt;" statement to incorporate revised interpretation of date ranges.&lt;/P&gt;</description>
    <pubDate>Thu, 10 Aug 2023 01:14:45 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2023-08-10T01:14:45Z</dc:date>
    <item>
      <title>Check matching criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-matching-criteria/m-p/888607#M351071</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have to check matching criteria on the following variables: age (+/- 3 years) gender dg_date (+/- 1 month).&lt;/P&gt;&lt;P&gt;How can I do?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;See example of data at below&lt;/P&gt;&lt;PRE&gt;data match;
  input Id  case_control match_caseid age gender dg_date : ddmmyy10. ;
  format dg_date ddmmyy10.;
datalines;
A1 Case	      20 F 20/08/2023
A2 Control A1 23 F 21/07/2023
A3 Control A1 22 F 22/09/2023
B1 Case	      30 M 01/06/2023
B2 Control B1 35 M 24/08/2023
B3 Control B1 33 M 12/06/2023
C1 Case	      40 M 26/05/2023
C2 Control C1 38 M 30/04/2023
D1 Case	      47 M 28/07/2023
D2 Control D1 41 M 29/06/2023
D3 Control D1 50 F 30/07/2023
D4 Control D1 63 M 31/07/2023
;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Aug 2023 16:31:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-matching-criteria/m-p/888607#M351071</guid>
      <dc:creator>Liamb</dc:creator>
      <dc:date>2023-08-09T16:31:11Z</dc:date>
    </item>
    <item>
      <title>Re: Check matching criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-matching-criteria/m-p/888611#M351075</link>
      <description>&lt;P&gt;Suggest that you run that data step and examine the results. It throws a lot of invalid data messages because of missing values.&lt;/P&gt;
&lt;P&gt;In datalines place . where a value&amp;nbsp; is missing and it may help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have no idea what you expect for a result. I think you need to expand a bit on exactly what you are checking for.&lt;/P&gt;
&lt;P&gt;age +/- 3 years from what?&lt;/P&gt;
&lt;P&gt;What check is to do be done for gender?&lt;/P&gt;
&lt;P&gt;Dg_date +/- month from what?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2023 16:47:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-matching-criteria/m-p/888611#M351075</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-09T16:47:55Z</dc:date>
    </item>
    <item>
      <title>Re: Check matching criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-matching-criteria/m-p/888619#M351078</link>
      <description>&lt;P&gt;I want to check if age (+/- 3 years), gender and dg_date (+/- 1 month) are the same for case and matched&amp;nbsp;control&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data step corrected&lt;/P&gt;&lt;PRE&gt;data match;
  input Id $  case_control $ match_caseid $ age gender $ dg_date : ddmmyy10. ;
  format dg_date ddmmyy10.;
datalines;
A1 Case    A1 20 F 20/08/2023
A2 Control A1 23 F 21/07/2023
A3 Control A1 22 F 22/09/2023
B1 Case    B1 30 M 1/06/2023
B2 Control B1 35 M 24/08/2023
B3 Control B1 33 M 12/06/2023
C1 Case    C1 40 M 26/05/2023
C2 Control C1 38 M 30/04/2023
D1 Case    D1 47 M 28/07/2023
D2 Control D1 41 M 29/06/2023
D3 Control D1 50 F 30/07/2023
D4 Control D1 63 M 31/07/2023
;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 09 Aug 2023 17:23:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-matching-criteria/m-p/888619#M351078</guid>
      <dc:creator>Liamb</dc:creator>
      <dc:date>2023-08-09T17:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: Check matching criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-matching-criteria/m-p/888627#M351082</link>
      <description>&lt;P&gt;And what does&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;(+/- 1 month) for dg_date mean.&amp;nbsp; Does it mean calendar months two month apart?&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I.e.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;are&amp;nbsp; &amp;nbsp;01jun2023&amp;nbsp; and 30apr2023 two months apart?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; or would it have to be some other criterion?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Aug 2023 18:16:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-matching-criteria/m-p/888627#M351082</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-08-09T18:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: Check matching criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-matching-criteria/m-p/888630#M351083</link>
      <description>&lt;P&gt;If all CASEs precede the relevant CONTROL candidates, then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data match;
  input Id $  case_control $ match_caseid $ age gender $ dg_date : ddmmyy10. ;
  format dg_date ddmmyy10.;
datalines;
A1 Case    A1 20 F 20/08/2023
A2 Control A1 23 F 21/07/2023
A3 Control A1 22 F 22/09/2023
B1 Case    B1 30 M 1/06/2023
B2 Control B1 35 M 24/08/2023
B3 Control B1 33 M 12/06/2023
C1 Case    C1 40 M 26/05/2023
C2 Control C1 38 M 30/04/2023
D1 Case    D1 47 M 28/07/2023
D2 Control D1 41 M 29/06/2023
D3 Control D1 50 F 30/07/2023
D4 Control D1 63 M 31/07/2023
run;


data want (drop=_:);
  set match
      match (obs=0 rename=(age=_age gender=_gender dg_date=_dg_date));

  if _n_=1 then do;
    declare hash h();
      h.definekey('id');
      h.definedata('_age','_gender','_dg_date');
      h.definedone();
  end;
    
  if case_control='Case' then do;
    _age=age;
    _gender=gender;
    _dg_date=dg_date;
    h.add();
  end;
  else do;
    _rc=h.find(key:match_caseid);
    if _rc^=0 then Match='Match_Caseid Not Found';
    else if gender=_gender and abs(age-_age)&amp;lt;=3
        and dg_date &amp;gt;  intnx('month',_dg_date,-1,'sameday') 
        and dg_date &amp;lt;= intnx('month',_dg_date,+1,'sameday')
        then Match='Yes';
    else Match='No ';
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Edit: minor change made to the "&lt;EM&gt;&lt;STRONG&gt;else if .... then Match='Yes'&lt;/STRONG&gt;&lt;/EM&gt;" statement to incorporate revised interpretation of date ranges.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2023 01:14:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-matching-criteria/m-p/888630#M351083</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-08-10T01:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Check matching criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-matching-criteria/m-p/888633#M351084</link>
      <description>(+/- 1 month) is the difference acceptable between dg_date for case and&lt;BR /&gt;dg_date for control, for example if case dg_date=08Aug2023 and control&lt;BR /&gt;dg_date must be between 09Jul2023 and 09Sep2023.&lt;BR /&gt;The maching criteria are satisfied if case and control have same age,&lt;BR /&gt;gender and dg_date&lt;BR /&gt;</description>
      <pubDate>Wed, 09 Aug 2023 18:37:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-matching-criteria/m-p/888633#M351084</guid>
      <dc:creator>Liamb</dc:creator>
      <dc:date>2023-08-09T18:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: Check matching criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-matching-criteria/m-p/888783#M351110</link>
      <description>&lt;P&gt;Thanks, it work&lt;/P&gt;</description>
      <pubDate>Thu, 10 Aug 2023 11:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-matching-criteria/m-p/888783#M351110</guid>
      <dc:creator>Liamb</dc:creator>
      <dc:date>2023-08-10T11:31:40Z</dc:date>
    </item>
  </channel>
</rss>

