<?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: Compare one variable in observation to different variable in all observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Compare-one-variable-in-observation-to-different-variable-in-all/m-p/613929#M179390</link>
    <description>&lt;P&gt;This code worked perfectly and accomplished exactly what I needed to accomplish. Thank you so much for your help, Kurt!&lt;/P&gt;</description>
    <pubDate>Thu, 26 Dec 2019 16:37:34 GMT</pubDate>
    <dc:creator>sasuser123451</dc:creator>
    <dc:date>2019-12-26T16:37:34Z</dc:date>
    <item>
      <title>Compare one variable in observation to different variable in all observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-one-variable-in-observation-to-different-variable-in-all/m-p/613926#M179387</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I am trying to determine therapy utilization rate based on the way that we have defined therapy use - ie within 180 days of diagnosis of the disease. I am trying to find a way to assign each ID (enrolid) its own denominator based on the number of people who were eligible for therapy at that time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Variables involved here: enrolid, index_date (date of diagnosis of the disease), and svcdate (date that therapy was received). So for each enrolid, I would compare the date of therapy (svcdate) to the date of diagnosis (index_date) for all other enrolid's and want to get a sum of all enrolids whose date of diagnosis (index_date) was within 180 days prior to the date of therapy.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;enrolid&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; index_date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;svcdate&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;denominator&lt;/P&gt;&lt;P&gt;123&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2/1/2011&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3/12/2011&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;?&lt;/P&gt;&lt;P&gt;456&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10/1/2012&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;11/4/2012&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;?&lt;/P&gt;&lt;P&gt;789&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1/1/2011&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3/6/2011&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So here, the denominator for enrolid #123 would be 2, because enrolids 123 and 789 both have index_dates that are within 180 days (6 months) prior to the svcdate for enrolid #123. Same thing for enrolid #789. The denominator for enrolid #456 would be 1 because it is the only enrolid with an index_date within 180 days of its svcdate.&amp;nbsp;There is only one observation per enrolid.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know this syntax is not correct (I do not know how to reference the variable of the observation we are currently looking at vs the variable from a different observation we are comparing to), but this is the general idea of what I am thinking:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want; set have; 
retain denominator 1 denominator_;
*setting denominator as one because each enrolid counts for its own denominator;

do while enrolid NE enrolid;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
**wrong syntax, but do while the enrolid of the observation we are comparing is not equal to the current enrolid ie compare to all other observations;

if intck('day',index_date,svcdate) &amp;gt; 0&amp;nbsp; and intck('day',index_date,svcdate) LE 180&amp;nbsp; &amp;nbsp; &amp;nbsp;
**wrong syntax, but compare this observation's svcdate to index_date of other observations;
*so I would want the svcdate to be the svcdate for the current observation and index_date to be the index_date for the observation we are comparing to;

then denominator+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; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;
else denominator=denominator;

end;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;I am using SAS Enterprise Guide 8.1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2019 16:20:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-one-variable-in-observation-to-different-variable-in-all/m-p/613926#M179387</guid>
      <dc:creator>sasuser123451</dc:creator>
      <dc:date>2019-12-26T16:20:31Z</dc:date>
    </item>
    <item>
      <title>Re: Compare one variable in observation to different variable in all observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-one-variable-in-observation-to-different-variable-in-all/m-p/613927#M179388</link>
      <description>&lt;P&gt;Something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select
  a.*,
  (select count(*) from have b where b.enrolid ne a.enrolid and abs(b.indexdate - a.svcdate) le 180)
from have a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 Dec 2019 16:31:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-one-variable-in-observation-to-different-variable-in-all/m-p/613927#M179388</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-26T16:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: Compare one variable in observation to different variable in all observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Compare-one-variable-in-observation-to-different-variable-in-all/m-p/613929#M179390</link>
      <description>&lt;P&gt;This code worked perfectly and accomplished exactly what I needed to accomplish. Thank you so much for your help, Kurt!&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2019 16:37:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Compare-one-variable-in-observation-to-different-variable-in-all/m-p/613929#M179390</guid>
      <dc:creator>sasuser123451</dc:creator>
      <dc:date>2019-12-26T16:37:34Z</dc:date>
    </item>
  </channel>
</rss>

