<?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: Selecting the closest 4 propensity scores as controls in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358473#M84240</link>
    <description>&lt;P&gt;I had assumed your SQL was working, but if it's not...if you post data we can work with we can help with code. Working off two records isn't going to work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you search on here you'll find instructions on how to post code a data step.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 13 May 2017 20:46:43 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2017-05-13T20:46:43Z</dc:date>
    <item>
      <title>Selecting the closest 4 propensity scores as controls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358457#M84230</link>
      <description>&lt;P&gt;Hello All!&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two data sets one which contains all of my cases and looks similar to this: It contains if the outcome occurred and since these are all cases the outcome variable is always 1, the date on which the outcome occurred, the zip code, and then the propensity score(PS) calculated previously: (n=45,000 named&amp;nbsp;&lt;SPAN&gt;CAL.PS_CASES1&lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;OUTCOME &amp;nbsp;OUTCOME_DATE &amp;nbsp;ZIPCODE &amp;nbsp; PS &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Id_t&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/01/05 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 33333 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .5680 &amp;nbsp; &amp;nbsp; &amp;nbsp; 32&lt;/P&gt;&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 03/26/09 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;55555 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .0337 &amp;nbsp; &amp;nbsp; &amp;nbsp; 6589&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second data set contains environmental data for each day by zipcode and also has a propensity score that was previously calculated. The data looks like this:&lt;/P&gt;&lt;P&gt;(n=1,530,000 named &lt;SPAN&gt;CAL.PS_CONT1 &lt;/SPAN&gt;)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;OUTCOME_DATE &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZIPCODE &amp;nbsp; &amp;nbsp; PS &amp;nbsp; &amp;nbsp;TEMP ....&amp;nbsp;...MEANNO2 &amp;nbsp; &amp;nbsp;Id_t&lt;/P&gt;&lt;P&gt;1/01/05 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;33333 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .0483 &amp;nbsp; &amp;nbsp; &amp;nbsp; 78 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 92 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1/01/05 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 55555 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .2569 &amp;nbsp; &amp;nbsp; &amp;nbsp; 85 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 72 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;03/26/09 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 55555 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.7802 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;65 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 80 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to select the 4 closest propensity scores, from the environmental data, for each one of my cases and call them controls. These four controls matched on closest propensity scores must be in a range of plus or minus 30 days from the outcome date of the specific case. I am trying to use proc sql to select these controls. This is the start of my code... I do not know how to specify selecting 4 controls per case instead of just one. I also am not sure if I need a right join statement. Any help would be greatly appreciated. Thank you in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;BR /&gt;create table PS_MATCH as&lt;BR /&gt;SELECT a.*,b.*,&lt;BR /&gt;ABS(A.OUTCOME_DATE-B.OUTCOME_DATE) AS ABSDATE&lt;/P&gt;&lt;P&gt;A.PS-B.PS AS PROP_SCORE,&lt;BR /&gt;ABS(CALCULATED PROP_SCORE) AS ABSPROP,&lt;BR /&gt;FROM CAL.PS_CASES1 AS A,&lt;BR /&gt;CAL.PS_CONT1 AS B&lt;BR /&gt;WHERE ABSDATE &amp;lt;= 30&lt;BR /&gt;GROUP BY ID_T;&lt;BR /&gt;QUIT;&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2017 18:11:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358457#M84230</guid>
      <dc:creator>SMcelroy1287</dc:creator>
      <dc:date>2017-05-13T18:11:34Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the closest 4 propensity scores as controls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358458#M84231</link>
      <description>&lt;P&gt;Can controls be used multiple times in a match? Essentially a greedy match algorithm.&lt;/P&gt;
&lt;P&gt;For starters you can look for a Mayo Clinic Propensity score matching?&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2017 18:14:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358458#M84231</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-13T18:14:49Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the closest 4 propensity scores as controls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358460#M84232</link>
      <description>&lt;P&gt;Yes, controls can be matched to multiple cases if it satisfies the conditions of closest propensity score and it is within the 60-day range of the case date.&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2017 18:25:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358460#M84232</guid>
      <dc:creator>SMcelroy1287</dc:creator>
      <dc:date>2017-05-13T18:25:34Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the closest 4 propensity scores as controls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358464#M84234</link>
      <description>&lt;P&gt;So assuming your code does find all 'valid' matches you can use SAS steps after to pick the closest 4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by caseID controlID descending matchScore;
run;

data want;
set have;
by caseID controlID;

if first.caseID then count=0;
count+1;

if&amp;nbsp;count &amp;lt;= 4;

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2017 19:06:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358464#M84234</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-13T19:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the closest 4 propensity scores as controls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358467#M84236</link>
      <description>&lt;P&gt;Just one possible correction I'd make to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s suggestion. If what she called matchscore is actually your absprop, I think you would want to leave off the DESCENDING option on your proc sort, so that the first one will be the one with the lowest absprop.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2017 19:38:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358467#M84236</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-13T19:38:28Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the closest 4 propensity scores as controls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358468#M84237</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13711"&gt;@art297&lt;/a&gt;&amp;nbsp;is correct,&amp;nbsp;I was assuming that a higher score is better in the code used above. If that's not true then remove the DESCENDING.&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2017 19:42:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358468#M84237</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-13T19:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the closest 4 propensity scores as controls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358471#M84238</link>
      <description>&lt;P&gt;Thank you for your suggestion. Yes, I would want the smallest absprop&amp;nbsp;scores so descending here would not work. I have not been able to figure out the first part of my code to generated the possible controls. Do you have any better ideas?&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2017 20:43:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358471#M84238</guid>
      <dc:creator>SMcelroy1287</dc:creator>
      <dc:date>2017-05-13T20:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the closest 4 propensity scores as controls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358472#M84239</link>
      <description>&lt;P&gt;Thank you for responding! I have not been able to generate my possible controls yet, but this code does look useful for when I do.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2017 20:44:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358472#M84239</guid>
      <dc:creator>SMcelroy1287</dc:creator>
      <dc:date>2017-05-13T20:44:07Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the closest 4 propensity scores as controls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358473#M84240</link>
      <description>&lt;P&gt;I had assumed your SQL was working, but if it's not...if you post data we can work with we can help with code. Working off two records isn't going to work.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you search on here you'll find instructions on how to post code a data step.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2017 20:46:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358473#M84240</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-13T20:46:43Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the closest 4 propensity scores as controls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358478#M84242</link>
      <description>&lt;P&gt;Ok, I have uploaded subsets of my data only including the variables I would like to select on. Preterm =outcome,&amp;nbsp;nbthdate&amp;nbsp;=outcome date, and ps=propensity score&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2017 21:34:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358478#M84242</guid>
      <dc:creator>SMcelroy1287</dc:creator>
      <dc:date>2017-05-13T21:34:04Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the closest 4 propensity scores as controls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358479#M84243</link>
      <description>&lt;P&gt;Without seeing example data and specifically what you want your resulting file to look like, we can't be sure. However, you should be able to modify the following:&lt;/P&gt;
&lt;PRE&gt;PROC SQL;
  create table PS_MATCH as
    SELECT a.*,
           b.outcome_date as boutcome_date format=date9.,
      ABS(A.OUTCOME_DATE-B.OUTCOME_DATE) AS ABSDATE,
      A.PS-B.PS AS PROP_SCORE,
      b.ps as bps,
      ABS(CALCULATED PROP_SCORE) AS ABSPROP
        FROM CAL.PS_CASES1 AS A,
          CAL.PS_CONT1 AS B
           WHERE a.id_t eq b.id_t and
                 a.zipcode eq b.zipcode and
                 ABSDATE &amp;lt;= 30
  ;
QUIT;

proc sort data=ps_match;
  by id_t absprop;
run;

data want (drop=count);
  set ps_match;
  by id_t;
  if first.id_t then count=0;
  count+1;
  if count &amp;lt;= 4;
run;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2017 21:33:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358479#M84243</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-13T21:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the closest 4 propensity scores as controls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358484#M84244</link>
      <description>&lt;P&gt;Thank you for your response! I tried running the code and I am receiving this ERROR: The following columns were not found in the contributing tables: ABSDATE. I have attached my log below.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;889   PROC SQL;
890    create table PS_MATCH as
891      SELECT a.*,
892             b.nbthdate as bnbthdate format=date9.,
893        A.nbthdate-B.nbthdate AS days,
894        abs(calculated days) as absdate,
895        A.PS-B.PS AS PROP_SCORE,
896        b.ps as bps,
897        ABS(CALCULATED PROP_SCORE) AS ABSPROP
898          FROM CAL.PS_CASES1 AS A,
899            CAL.PS_CONT1 AS B
900             WHERE a.id_t=b.id_t and ABSDATE &amp;lt;= 30
901    ;
ERROR: The following columns were not found in the contributing tables: ABSDATE.
902  QUIT;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds



903  proc sort data=ps_match;
904    by id_t absprop;
905  run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2017 22:40:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358484#M84244</guid>
      <dc:creator>SMcelroy1287</dc:creator>
      <dc:date>2017-05-13T22:40:55Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the closest 4 propensity scores as controls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358485#M84245</link>
      <description>I have attached a subset of my data in .txt format earlier in the feed if you need to work with actual data.</description>
      <pubDate>Sat, 13 May 2017 22:43:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358485#M84245</guid>
      <dc:creator>SMcelroy1287</dc:creator>
      <dc:date>2017-05-13T22:43:54Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting the closest 4 propensity scores as controls</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358486#M84246</link>
      <description>&lt;P&gt;Can't test your code since id_t isn't in your controls file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, try adding calculated before absdate. i.e.,&lt;/P&gt;
&lt;PRE&gt;WHERE a.id_t=b.id_t and calculated ABSDATE &amp;lt;= 30&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 13 May 2017 23:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-the-closest-4-propensity-scores-as-controls/m-p/358486#M84246</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-05-13T23:09:16Z</dc:date>
    </item>
  </channel>
</rss>

