<?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 based on age and sex in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-age-and-sex/m-p/929259#M365642</link>
    <description>&lt;P&gt;Here is one way. This uses a Data step merge, which is different than an inner join.&lt;/P&gt;
&lt;P&gt;You did not provide any example data so this a small dummy example. The possible controls do contain sex age combinations that do not appear in the example experimental group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/* generate a possible list of controls */
data work.poss;
   do CID = 100 to 1000;
      sex = rand('BERNOULLI',.5)+1;
      age = rand('integer',14,18);
      randomizer = rand('uniform');
      output;
   end;
   label CID='ID in control set';
run;

/* randomize the order of the possible
   controls
*/
proc sort data=work.poss;
   by sex age randomizer;
run;

/* "experimental" set */
data work.exp;
   input id sex age;
datalines;
1 1 15 
2 1 15 
3 1 15 
6 1 16 
4 2 15 
5 2 15 
7 2 16 
8 2 16
;

proc sort data=work.exp;
   by sex age ;
run;

data work.want;
   merge work.poss (in=in1)
         work.exp (in=in2)
   ;
   by sex age;
   lid=lag(id);
   if in2;
   if id=lid then delete;
   drop lid randomizer;
run;
&lt;/PRE&gt;
&lt;P&gt;The way a match merge with BY variables works when there are multiples of the By variables in both data sets is the last observation of the smaller group of BY values will get matched with all the remaining ones from the other set. So we use the LAG function to identify the previous ID of the experimental group (&lt;STRONG&gt;big&lt;/STRONG&gt; assumption that is smaller than the possible controls ). If the ID repeats then remove. The IN= option provides a temporary variable that indicates whether that data set contributed to the current observation that is 1/0 valued for true/false. We only select the ones that have a contribution from the experimental group with the "if in2;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This does include a randomization for the possible control matches.&lt;/P&gt;</description>
    <pubDate>Wed, 22 May 2024 15:57:56 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-05-22T15:57:56Z</dc:date>
    <item>
      <title>matching based on age and sex</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-age-and-sex/m-p/929234#M365629</link>
      <description>&lt;P&gt;hello.&lt;BR /&gt;I am a SAS beginner.&lt;/P&gt;&lt;P&gt;I have an experimental group, and I need to build a control group.&lt;BR /&gt;A control group must be created by matching control group subjects 1:1 based on two variables: age and sex of the experimental group.&lt;/P&gt;&lt;P&gt;Matching should be done using only those two variables, not the propensity score.&lt;/P&gt;&lt;P&gt;Should I use proc psmatch or&amp;nbsp;inner join?&lt;BR /&gt;I would appreciate it if you could provide detailed code.&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2024 09:59:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-based-on-age-and-sex/m-p/929234#M365629</guid>
      <dc:creator>sasinitialuser</dc:creator>
      <dc:date>2024-05-22T09:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: matching based on age and sex</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-age-and-sex/m-p/929259#M365642</link>
      <description>&lt;P&gt;Here is one way. This uses a Data step merge, which is different than an inner join.&lt;/P&gt;
&lt;P&gt;You did not provide any example data so this a small dummy example. The possible controls do contain sex age combinations that do not appear in the example experimental group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/* generate a possible list of controls */
data work.poss;
   do CID = 100 to 1000;
      sex = rand('BERNOULLI',.5)+1;
      age = rand('integer',14,18);
      randomizer = rand('uniform');
      output;
   end;
   label CID='ID in control set';
run;

/* randomize the order of the possible
   controls
*/
proc sort data=work.poss;
   by sex age randomizer;
run;

/* "experimental" set */
data work.exp;
   input id sex age;
datalines;
1 1 15 
2 1 15 
3 1 15 
6 1 16 
4 2 15 
5 2 15 
7 2 16 
8 2 16
;

proc sort data=work.exp;
   by sex age ;
run;

data work.want;
   merge work.poss (in=in1)
         work.exp (in=in2)
   ;
   by sex age;
   lid=lag(id);
   if in2;
   if id=lid then delete;
   drop lid randomizer;
run;
&lt;/PRE&gt;
&lt;P&gt;The way a match merge with BY variables works when there are multiples of the By variables in both data sets is the last observation of the smaller group of BY values will get matched with all the remaining ones from the other set. So we use the LAG function to identify the previous ID of the experimental group (&lt;STRONG&gt;big&lt;/STRONG&gt; assumption that is smaller than the possible controls ). If the ID repeats then remove. The IN= option provides a temporary variable that indicates whether that data set contributed to the current observation that is 1/0 valued for true/false. We only select the ones that have a contribution from the experimental group with the "if in2;"&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This does include a randomization for the possible control matches.&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2024 15:57:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-based-on-age-and-sex/m-p/929259#M365642</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-05-22T15:57:56Z</dc:date>
    </item>
    <item>
      <title>Re: matching based on age and sex</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-age-and-sex/m-p/929274#M365644</link>
      <description>Inner join seems like an interesting option as that could drop experimental cases which is a tad off. Usually the matching algorithms will be adjusted instead if no matches are found rather than dropping but if that's what you're after, inner join is correct. &lt;BR /&gt;A left join is the typical method. What would you want to do with multiple matches?</description>
      <pubDate>Wed, 22 May 2024 16:54:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-based-on-age-and-sex/m-p/929274#M365644</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-05-22T16:54:07Z</dc:date>
    </item>
    <item>
      <title>Re: matching based on age and sex</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-age-and-sex/m-p/929944#M365885</link>
      <description>&lt;P&gt;I want to create a control group that is the same or similar in age and gender to the experimental group.&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2024 07:47:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-based-on-age-and-sex/m-p/929944#M365885</guid>
      <dc:creator>sasinitialuser</dc:creator>
      <dc:date>2024-05-28T07:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: matching based on age and sex</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-age-and-sex/m-p/929981#M365897</link>
      <description>And if there is no match to your experimental group you'll drop the experimental case? That is what an inner join would do.</description>
      <pubDate>Tue, 28 May 2024 16:02:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-based-on-age-and-sex/m-p/929981#M365897</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2024-05-28T16:02:53Z</dc:date>
    </item>
    <item>
      <title>Re: matching based on age and sex</title>
      <link>https://communities.sas.com/t5/SAS-Programming/matching-based-on-age-and-sex/m-p/930017#M365913</link>
      <description>Yes I'll drop some of experimental group.&lt;BR /&gt;</description>
      <pubDate>Wed, 29 May 2024 02:02:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/matching-based-on-age-and-sex/m-p/930017#M365913</guid>
      <dc:creator>sasinitialuser</dc:creator>
      <dc:date>2024-05-29T02:02:05Z</dc:date>
    </item>
  </channel>
</rss>

