<?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 matching based on three criteria in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/501785#M133839</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  input patientid  dg_date mmddyy10. age sex;
datalines;
1 5/5/2009 18 1
2  1/2/2007 60 1
3  2/2/2004 70 0
;
run;
 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
  input patientid  date2 mmddyy10. age sex;
datalines;
4 5/5/2009 18 1
4 10/6/2009 18 1
5  1/2/2007 60 1
5 1/1/2007 60 1
6  2/2/2004 79 0
6 3/3/2004  79 0
6  1/1/2004  79 0
;
run;
 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have two data a and b. Data a has the diagnosis date, I want to match data a to data b by selecting ids which match on age, sex, and have any date "date2" that matches exactly the dg_date.&lt;/P&gt;&lt;P&gt;output (1 case and 0 control)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id label&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;4&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;5&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 05 Oct 2018 08:59:08 GMT</pubDate>
    <dc:creator>lillymaginta</dc:creator>
    <dc:date>2018-10-05T08:59:08Z</dc:date>
    <item>
      <title>matching based on three criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/501785#M133839</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  input patientid  dg_date mmddyy10. age sex;
datalines;
1 5/5/2009 18 1
2  1/2/2007 60 1
3  2/2/2004 70 0
;
run;
 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
  input patientid  date2 mmddyy10. age sex;
datalines;
4 5/5/2009 18 1
4 10/6/2009 18 1
5  1/2/2007 60 1
5 1/1/2007 60 1
6  2/2/2004 79 0
6 3/3/2004  79 0
6  1/1/2004  79 0
;
run;
 &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have two data a and b. Data a has the diagnosis date, I want to match data a to data b by selecting ids which match on age, sex, and have any date "date2" that matches exactly the dg_date.&lt;/P&gt;&lt;P&gt;output (1 case and 0 control)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;id label&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;4&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;5&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 08:59:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/501785#M133839</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2018-10-05T08:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: matching based on three criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/501788#M133841</link>
      <description>&lt;P&gt;Well, if I understand you correctly:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table want as
  select  a.id,
          case when b.patientid ne . then 1 else 0 end as label
  from    a a
  left join b b
  on      a.age=b.age
  and     a.sex=b.sex
  and     a.dg_date=date2;&lt;BR /&gt;quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Oct 2018 09:19:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/501788#M133841</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-05T09:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: matching based on three criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/501798#M133845</link>
      <description>&lt;P&gt;Thank you RW9. Although the specification you included seems correct, the output is not correct so it includes only ids from data a.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 09:46:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/501798#M133845</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2018-10-05T09:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: matching based on three criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/501803#M133846</link>
      <description>&lt;P&gt;Ok, you would need one for each way then:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table want as
  select  a.id,
          case when b.patientid ne . then 1 else 0 end as label
  from    a a
  left join b b
  on      a.age=b.age
  and     a.sex=b.sex
  and     a.dg_date=date2&lt;BR /&gt;  union all&lt;BR /&gt;  select  a.id,&lt;BR /&gt;          case when b.patientid ne . then 1 else 0 end as label&lt;BR /&gt;  from    b a&lt;BR /&gt;  left join a b&lt;BR /&gt;  on      a.age=b.age&lt;BR /&gt;  and     a.sex=b.sex&lt;BR /&gt;  and     a.date2=b.dg_date&lt;BR /&gt;;&lt;BR /&gt;quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Oct 2018 09:57:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/501803#M133846</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-05T09:57:19Z</dc:date>
    </item>
    <item>
      <title>Re: matching based on three criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/501807#M133848</link>
      <description>&lt;P&gt;thank you for the prompt response but the output is still not correct. id's number 3 and 6 should not be included in the dataset and the output listed id 5 once as 1 (case) and one as 0 (control), it should be only a control (0).&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 10:05:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/501807#M133848</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2018-10-05T10:05:59Z</dc:date>
    </item>
    <item>
      <title>Re: matching based on three criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/501814#M133850</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  input patientid  dg_date : mmddyy10. age sex;
  format  dg_date  mmddyy10.;
datalines;
1 5/5/2009 18 1
2  1/2/2007 60 1
3  2/2/2004 70 0
;
run;
data b;
  input patientid  date2 : mmddyy10. age sex;
  format date2  mmddyy10.;
datalines;
4 5/5/2009 18 1
4 10/6/2009 18 1
5  1/2/2007 60 1
5 1/1/2007 60 1
6  2/2/2004 79 0
6 3/3/2004  79 0
6  1/1/2004  79 0
;
run;

proc sort data=a out=temp_a;
by  dg_date  age sex;
run;
proc sort data=b out=temp_b;
by  date2  age sex;
run;
data temp;
 merge temp_a(in=ina) 
 temp_b(rename=(date2=dg_date patientid=_patientid) in=inb);
 by  dg_date  age sex;
 if ina and inb;
run;
data want;
 set temp;
 id=patientid;label=1;output;
 id=_patientid;label=0;output;
 keep id label;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Oct 2018 10:19:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/501814#M133850</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-10-05T10:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: matching based on three criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/501922#M133900</link>
      <description>&lt;P&gt;Perfect Ksharp!&amp;nbsp;I have a large pool of controls, so would it be possible to use the same code to match 1 case&amp;nbsp;to more than one control (e.g. 16)?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Oct 2018 14:34:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/501922#M133900</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2018-10-05T14:34:23Z</dc:date>
    </item>
    <item>
      <title>Re: matching based on three criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/502099#M133980</link>
      <description>&lt;P&gt;Technically , it could.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Post your data and output to explain your question more details.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Oct 2018 10:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/502099#M133980</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-10-06T10:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: matching based on three criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/502204#M134029</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  input patientid  dg_date : mmddyy10. age sex;
  format  dg_date  mmddyy10.;
datalines;
1 5/5/2009 18 1
2  1/2/2007 60 1
3  2/2/2004 70 0
;
run;

data b;
  input patientid  date2 : mmddyy10. age sex;
  format date2  mmddyy10.;
datalines;
4 5/5/2009 18 1
4 10/6/2009 18 1
5  1/2/2007 60 1
5 1/1/2007 60 1
6  2/2/2004 79 0
6 3/3/2004  79 0
6  1/1/2004  79 0
7 5/5/2009 18 1
7 10/6/2009 18 1
8  1/2/2007 60 1
8 1/1/2007 60 1
9  2/2/2004 79 0
9 3/3/2004  79 0
9  1/1/2004  79 0
10 5/5/2009 18 1
10 10/6/2009 18 1
11  1/2/2007 60 1
11 1/1/2007 60 1
12  2/2/2004 79 0
12 3/3/2004  79 0
12  1/1/2004  79 0
13 5/5/2009 18 1
13 10/6/2009 18 1
14  1/2/2007 60 1
14 1/1/2007 60 1
15  2/2/2004 79 0
15 3/3/2004  79 0
15  1/1/2004  79 0
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;output&lt;/P&gt;&lt;P&gt;id label&lt;/P&gt;&lt;P&gt;1&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; 1&lt;/P&gt;&lt;P&gt;4&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;5&amp;nbsp; 0&lt;/P&gt;&lt;P&gt;7 0&lt;/P&gt;&lt;P&gt;8 0&lt;/P&gt;&lt;P&gt;10 0&lt;/P&gt;&lt;P&gt;11 0&lt;/P&gt;&lt;P&gt;13 0&lt;/P&gt;&lt;P&gt;14 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just to avoid lengthy data, in this data, each case from a would match to 4 controls from b&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Oct 2018 00:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/502204#M134029</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2018-10-07T00:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: matching based on three criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/502234#M134042</link>
      <description>&lt;P&gt;Yes. I could. Just add one more PROC SORT at bottom of code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data a;
  input patientid  dg_date : mmddyy10. age sex;
  format  dg_date  mmddyy10.;
datalines;
1 5/5/2009 18 1
2  1/2/2007 60 1
3  2/2/2004 70 0
;
run;

data b;
  input patientid  date2 : mmddyy10. age sex;
  format date2  mmddyy10.;
datalines;
4 5/5/2009 18 1
4 10/6/2009 18 1
5  1/2/2007 60 1
5 1/1/2007 60 1
6  2/2/2004 79 0
6 3/3/2004  79 0
6  1/1/2004  79 0
7 5/5/2009 18 1
7 10/6/2009 18 1
8  1/2/2007 60 1
8 1/1/2007 60 1
9  2/2/2004 79 0
9 3/3/2004  79 0
9  1/1/2004  79 0
10 5/5/2009 18 1
10 10/6/2009 18 1
11  1/2/2007 60 1
11 1/1/2007 60 1
12  2/2/2004 79 0
12 3/3/2004  79 0
12  1/1/2004  79 0
13 5/5/2009 18 1
13 10/6/2009 18 1
14  1/2/2007 60 1
14 1/1/2007 60 1
15  2/2/2004 79 0
15 3/3/2004  79 0
15  1/1/2004  79 0
;
run;

proc sort data=a out=temp_a;
by  dg_date  age sex;
run;
proc sort data=b out=temp_b;
by  date2  age sex;
run;
data temp;
 merge temp_a(in=ina) 
 temp_b(rename=(date2=dg_date patientid=_patientid) in=inb);
 by  dg_date  age sex;
 if ina and inb;
run;
data want;
 set temp;
 id=patientid;label=1;output;
 id=_patientid;label=0;output;
 keep id label;
run;

proc sort data=want out=final_want nodupkey;
by id label ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 07 Oct 2018 10:15:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/502234#M134042</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-10-07T10:15:30Z</dc:date>
    </item>
    <item>
      <title>Re: matching based on three criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/676783#M204087</link>
      <description>Hi Ksharp,&lt;BR /&gt;I am looking for exactly the same (matching controls for cases based on Age, Sex and Date) but I did not follow the code which picks ups 3 controls for every case (randomly). How to achieve this random selection? Can you please provide the sas code using the same variables in this example?&lt;BR /&gt;Thanks,&lt;BR /&gt;Sat</description>
      <pubDate>Fri, 14 Aug 2020 16:12:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/676783#M204087</guid>
      <dc:creator>sms1891</dc:creator>
      <dc:date>2020-08-14T16:12:37Z</dc:date>
    </item>
    <item>
      <title>Re: matching based on three criteria</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/676953#M204148</link>
      <description>Sorry. I can't understand your question. if you want randomly select obs ,&lt;BR /&gt;could try PROC SURVEYSELECT .&lt;BR /&gt;&lt;BR /&gt;Better start a new topic to let more sas user to discuss it .</description>
      <pubDate>Sat, 15 Aug 2020 11:51:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-based-on-three-criteria/m-p/676953#M204148</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-08-15T11:51:44Z</dc:date>
    </item>
  </channel>
</rss>

