<?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: PROPENSITY SCORE LOOP in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROPENSITY-SCORE-LOOP/m-p/657604#M197077</link>
    <description>I have tried to run this one- but I can't even run it. I don't have an&lt;BR /&gt;output example.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%macro match_by_yr(inset=, outset=, startyear=, endyear=, matches=,&lt;BR /&gt;calip=, ctrlrestvar=, pscorevar=, treatvar=);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql; drop table &amp;amp;outset; quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%do i=&amp;amp;startyear %to &amp;amp;endyear;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%put Year &amp;amp;i;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* generate treated dataset for this firm-year */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;create table _treat as&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;select unique_id as idT,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;amp;pscorevar as pscoreT&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;from &amp;amp;inset&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;where yr = &amp;amp;i and &amp;amp;treatvar = 1;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* generate non-treated dataset for this firm-year */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;create table _nontreat as&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;select unique_id as idC,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;amp;pscorevar as pscoreC&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;from &amp;amp;inset&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;where yr = &amp;amp;i and &amp;amp;treatvar = 0 and &amp;amp;ctrlrestvar=0;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;select count(*) into :obs_count from _treat;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;select count(*) into :obs_count2 from _nontreat;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%if (&amp;amp;obs_count ge 1) and (&amp;amp;obs_count2 ge 1) %then %do;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* match */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%PSMatching(datatreatment= _treat,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;datacontrol= _nontreat,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;method= NN,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;numberofcontrols= &amp;amp;matches,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;caliper=&amp;amp;calip,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;replacement= no,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;out = _matches);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;*if a firm, either control or treatment, is selected in a year, then it can&lt;BR /&gt;not be selected again in future years;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;create table &amp;amp;inset&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;as select a.*, b.IdSelectedControl as&lt;BR /&gt;id_delec from &amp;amp;inset as a left join _matches as b&lt;BR /&gt;&lt;BR /&gt;on a.unique_id=b.IdSelectedControl;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;create table &amp;amp;inset&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;as select a.*, b.MatchedToTreatID as&lt;BR /&gt;id_delet from &amp;amp;inset as a left join _matches as b&lt;BR /&gt;&lt;BR /&gt;on a.unique_id=b.MatchedToTreatID;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data &amp;amp;inset;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;set &amp;amp;inset;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if not missing(id_delet) or not&lt;BR /&gt;missing(id_delec) then delete;&lt;BR /&gt;&lt;BR /&gt;drop id_delet id_delec;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* Start the dataset if First firm-industry */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%if &amp;amp;i = 1 %then&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%do;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data &amp;amp;outset;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;set _matches;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* otherwise append new matches to the running dataset */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%else&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%do;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data &amp;amp;outset;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;set &amp;amp;outset _matches;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* clean up temp datasets for next iteration */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;drop table _matches;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%mend match_by_yr;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Thu, 11 Jun 2020 17:00:11 GMT</pubDate>
    <dc:creator>HEB1</dc:creator>
    <dc:date>2020-06-11T17:00:11Z</dc:date>
    <item>
      <title>PROPENSITY SCORE LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROPENSITY-SCORE-LOOP/m-p/657593#M197071</link>
      <description>&lt;P&gt;Hi- I am looking for a code that can match panel data with years and industry only for pre- period. My modal is DID&amp;nbsp; Y=post*mandatory +Fixed effects.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mandatory is a dummy =1 or 0 represents my control and treatment (treatment is 1). Post is a dummy equals 1 after event.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a panel data with 37 firms as treatment (mandatory=1).&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to match on pre- period based on variables "before_after_event years" (that is all years between&amp;nbsp; (-1)-(-4)) and "SIC_2digit".&amp;nbsp;&lt;/P&gt;&lt;P&gt;the propensity should be run on variables "E", "leverage" and "AT".&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. I try to find a code but didn't see anything that can work.&lt;/P&gt;&lt;P&gt;2.When&amp;nbsp; "before_after_event years" is &amp;gt;= o , I do not need to match anymore- how can I build my sample for that? the pre- should be match but the post does not?&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. I prefer to do not loose treatment firms&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;HB&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 16:32:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROPENSITY-SCORE-LOOP/m-p/657593#M197071</guid>
      <dc:creator>HEB1</dc:creator>
      <dc:date>2020-06-11T16:32:50Z</dc:date>
    </item>
    <item>
      <title>Re: PROPENSITY SCORE LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROPENSITY-SCORE-LOOP/m-p/657600#M197074</link>
      <description>&lt;P&gt;Can you post what code you tried and what did not work. As well as a sample of expected output.&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 16:52:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROPENSITY-SCORE-LOOP/m-p/657600#M197074</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-06-11T16:52:02Z</dc:date>
    </item>
    <item>
      <title>Re: PROPENSITY SCORE LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROPENSITY-SCORE-LOOP/m-p/657604#M197077</link>
      <description>I have tried to run this one- but I can't even run it. I don't have an&lt;BR /&gt;output example.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%macro match_by_yr(inset=, outset=, startyear=, endyear=, matches=,&lt;BR /&gt;calip=, ctrlrestvar=, pscorevar=, treatvar=);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql; drop table &amp;amp;outset; quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%do i=&amp;amp;startyear %to &amp;amp;endyear;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%put Year &amp;amp;i;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* generate treated dataset for this firm-year */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;create table _treat as&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;select unique_id as idT,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;amp;pscorevar as pscoreT&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;from &amp;amp;inset&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;where yr = &amp;amp;i and &amp;amp;treatvar = 1;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* generate non-treated dataset for this firm-year */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;create table _nontreat as&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;select unique_id as idC,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;amp;pscorevar as pscoreC&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;from &amp;amp;inset&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;where yr = &amp;amp;i and &amp;amp;treatvar = 0 and &amp;amp;ctrlrestvar=0;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;select count(*) into :obs_count from _treat;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql noprint;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;select count(*) into :obs_count2 from _nontreat;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%if (&amp;amp;obs_count ge 1) and (&amp;amp;obs_count2 ge 1) %then %do;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* match */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%PSMatching(datatreatment= _treat,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;datacontrol= _nontreat,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;method= NN,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;numberofcontrols= &amp;amp;matches,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;caliper=&amp;amp;calip,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;replacement= no,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;out = _matches);&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;*if a firm, either control or treatment, is selected in a year, then it can&lt;BR /&gt;not be selected again in future years;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;create table &amp;amp;inset&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;as select a.*, b.IdSelectedControl as&lt;BR /&gt;id_delec from &amp;amp;inset as a left join _matches as b&lt;BR /&gt;&lt;BR /&gt;on a.unique_id=b.IdSelectedControl;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;create table &amp;amp;inset&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;as select a.*, b.MatchedToTreatID as&lt;BR /&gt;id_delet from &amp;amp;inset as a left join _matches as b&lt;BR /&gt;&lt;BR /&gt;on a.unique_id=b.MatchedToTreatID;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data &amp;amp;inset;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;set &amp;amp;inset;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if not missing(id_delet) or not&lt;BR /&gt;missing(id_delec) then delete;&lt;BR /&gt;&lt;BR /&gt;drop id_delet id_delec;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* Start the dataset if First firm-industry */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%if &amp;amp;i = 1 %then&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%do;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data &amp;amp;outset;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;set _matches;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* otherwise append new matches to the running dataset */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%else&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%do;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data &amp;amp;outset;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;set &amp;amp;outset _matches;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/* clean up temp datasets for next iteration */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;drop table _matches;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%end;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;%mend match_by_yr;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Thu, 11 Jun 2020 17:00:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROPENSITY-SCORE-LOOP/m-p/657604#M197077</guid>
      <dc:creator>HEB1</dc:creator>
      <dc:date>2020-06-11T17:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: PROPENSITY SCORE LOOP</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROPENSITY-SCORE-LOOP/m-p/657660#M197114</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/148688"&gt;@HEB1&lt;/a&gt;&amp;nbsp; What were you trying to do with that code you posted? I do not see how it is related to your objective or the data you provided. It will be tricky to give a solution without details of what is not working in code you've tried, and an output example.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, when you post SAS code, use use the "little running man" button.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="mklangley_1-1591902086298.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/42725i01E513F7DDE52902/image-size/medium?v=v2&amp;amp;px=400" role="button" title="mklangley_1-1591902086298.png" alt="mklangley_1-1591902086298.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jun 2020 19:10:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROPENSITY-SCORE-LOOP/m-p/657660#M197114</guid>
      <dc:creator>mklangley</dc:creator>
      <dc:date>2020-06-11T19:10:07Z</dc:date>
    </item>
  </channel>
</rss>

