<?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: Matching many to one based on scores in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Matching-many-to-one-based-on-scores/m-p/725683#M225454</link>
    <description>Sure, how did you write your original code? It's likely easiest to modify the code you already have. &lt;BR /&gt;The simplest way is to add a distance counter to the closest and then just filter based on the distance counter, not sure what approach you're using but that is how I'd do it. &lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Otherwise you may also want to take a look at PROC PSMATCH which does propensity matching and you can specify the N:M there as an option.</description>
    <pubDate>Fri, 12 Mar 2021 00:04:45 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-03-12T00:04:45Z</dc:date>
    <item>
      <title>Matching many to one based on scores</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-many-to-one-based-on-scores/m-p/725669#M225443</link>
      <description>&lt;P&gt;I have the following dataset&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
  input period	key_id	treat	ps_score
;
DATALINES;
59	1004	0	0.0701784726
59	1078	0	0.1496074832
59	1209	0	0.1325333248
59	1300	0	0.1555762808
59	1327	0	0.0469939511
59	1523	1	0.0531098455
59	1854	1	0.0411252176
61	1004	0	0.1085249132
61	1008	0	0.1531924709
61	1078	0	0.0963164678
61	1102	0	0.0962037147
61	1300	0	0.0684734650
61	2402	0	0.1030826279
61	3023	1	0.0242288199
61	3044	1	0.0848487298
61	4033	1	0.0024468050
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;First, I wish to do one to one matching as follows.: Match each key_id that has treat = 1 to a key_id with treat = 0 in the same period group where their absolute difference in ps_score is the smallest. This produces the following dataset:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA want1;
  input period	key_id	matched_id;
DATALINES;
59	1523	1327
59	1854	1327
61	3023	1300
61	3044	1102
61	4033	1300

;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For example, in period=59, for key_id=1523 (which has treat=1), the absolute difference in ps_score with key_id=1327 (which has treat=0 and is in the same period) is 0.006115894, which is the smallest. So in the want1 dataset, the matched_id for key_id=1523 is 1327. Other entries follow the same rule.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want to do next is 2-1 matching, so that each treat=1 is matched to the closest two key_id with treat=0 in the same period with the closest ps_score. The resultant dataset is as follows:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA want2;
  input period	key_id	matched_id;
DATALINES;
59	1523	1327
59	1523	1004
59	1854	1327
59	1854	1004
61	3023	1300
61	3023	1102
61	3044	1102
61	3044	1078
61	4033	1300
61	4033	1102
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;For example, for key_id=1523 in period=59, after it is matched to 1327, we look for the key_id with treat=0 that has the next smallest absolute difference in terms of ps_score. This corresponds to key_id=1004 (the absolute difference in ps_score is 0.017068627). So, in this 2-1 match, 1523 is matched with two observations.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is it possible to write a general code for this so that I can choose N:1 match (following the same rules as above) where I have illustrated the cases for N=1, 2 above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 22:45:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-many-to-one-based-on-scores/m-p/725669#M225443</guid>
      <dc:creator>elbarto</dc:creator>
      <dc:date>2021-03-11T22:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: Matching many to one based on scores</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Matching-many-to-one-based-on-scores/m-p/725683#M225454</link>
      <description>Sure, how did you write your original code? It's likely easiest to modify the code you already have. &lt;BR /&gt;The simplest way is to add a distance counter to the closest and then just filter based on the distance counter, not sure what approach you're using but that is how I'd do it. &lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Otherwise you may also want to take a look at PROC PSMATCH which does propensity matching and you can specify the N:M there as an option.</description>
      <pubDate>Fri, 12 Mar 2021 00:04:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Matching-many-to-one-based-on-scores/m-p/725683#M225454</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-12T00:04:45Z</dc:date>
    </item>
  </channel>
</rss>

