<?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: Defining a variable within a date interval in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Defining-a-variable-within-a-date-interval/m-p/749048#M80693</link>
    <description>&lt;P&gt;What is your definition of "last month".&amp;nbsp; &amp;nbsp;In your example, you apparently mean all the dates &lt;EM&gt;&lt;STRONG&gt;including&lt;/STRONG&gt;&lt;/EM&gt; the &lt;EM&gt;&lt;STRONG&gt;date exactly one month prior&lt;/STRONG&gt;&lt;/EM&gt; (i.e. for 7/19/2020 totals, include 6/19/2020).&amp;nbsp; Is that correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On the date 1/31/2020 you want not only all of January, but also the last date of December, right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, then&amp;nbsp;for October 30, 2020 you would want&amp;nbsp; Sep 30-Oct30.&amp;nbsp; &amp;nbsp;But consider October 31, 2020.&amp;nbsp; There is no Sep 31, so would it be Oct 1- Oct31,&amp;nbsp; or Sep 30-Oct31?&amp;nbsp; &amp;nbsp;In such cases, what is your definition of "the date exactly one month prior"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 19 Jun 2021 20:14:22 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2021-06-19T20:14:22Z</dc:date>
    <item>
      <title>Defining a variable within a date interval</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Defining-a-variable-within-a-date-interval/m-p/749036#M80690</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I have a dataset looks like this:&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="77"&gt;
&lt;P&gt;Location&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="93"&gt;
&lt;P&gt;Date&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;Number of warnings (N)&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="210"&gt;
&lt;P&gt;Number of correct warnings (T)&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="77"&gt;
&lt;P&gt;A&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="93"&gt;
&lt;P&gt;06/19/2020&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="210"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="77"&gt;
&lt;P&gt;A&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="93"&gt;
&lt;P&gt;06/29/2020&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="210"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="77"&gt;
&lt;P&gt;A&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="93"&gt;
&lt;P&gt;06/30/2020&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="210"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="77"&gt;
&lt;P&gt;A&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="93"&gt;
&lt;P&gt;07/1/2020&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="210"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="77"&gt;
&lt;P&gt;A&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="93"&gt;
&lt;P&gt;07/05/2020&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;7&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="210"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="77"&gt;
&lt;P&gt;A&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="93"&gt;
&lt;P&gt;07/15/2020&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="210"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="77"&gt;
&lt;P&gt;A&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="93"&gt;
&lt;P&gt;07/19/2020&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="210"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="77"&gt;
&lt;P&gt;A&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="93"&gt;
&lt;P&gt;….&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;…&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="210"&gt;
&lt;P&gt;…&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="77"&gt;
&lt;P&gt;B&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="93"&gt;
&lt;P&gt;05/12/2020&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="210"&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="77"&gt;
&lt;P&gt;B&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="93"&gt;
&lt;P&gt;05/24/2020&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="210"&gt;
&lt;P&gt;0&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="77"&gt;
&lt;P&gt;B&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="93"&gt;
&lt;P&gt;05/27/2020&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="210"&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="77"&gt;
&lt;P&gt;B&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="93"&gt;
&lt;P&gt;…&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="160"&gt;
&lt;P&gt;…&lt;/P&gt;
&lt;/TD&gt;
&lt;TD width="210"&gt;
&lt;P&gt;….&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;For each specific “Date” I want to calculate R=Sum(T)/Sum(N) during the last month. For example, if we consider Location “A” and Date “07/19/2020”, I want to have R=(0+1+3+1+3+2)/(2+7+4+1+5+3).&lt;/P&gt;
&lt;P&gt;Any help is appreciated!&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 19 Jun 2021 16:46:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Defining-a-variable-within-a-date-interval/m-p/749036#M80690</guid>
      <dc:creator>Bright</dc:creator>
      <dc:date>2021-06-19T16:46:51Z</dc:date>
    </item>
    <item>
      <title>Re: Defining a variable within a date interval</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Defining-a-variable-within-a-date-interval/m-p/749041#M80691</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;Here you are.&lt;/P&gt;
&lt;P&gt;A hash table look-up would be much faster though.&lt;/P&gt;
&lt;P&gt;Solution published here is fine unless you have Gigabytes of data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC DATASETS library=WORK memtype=DATA NoList;
 delete have0-have2 want ; run;
QUIT;

data have0;
infile cards delimiter='|';
input Location $ Date $ Nbr_warnings_N Nbr_correct_warnings_T;
datedate=input(date,mmddyy10.);
datedateMinus1Month=INTNX('MONTH',datedate,-1,'SAMEDAY');
format datedate datedateMinus1Month date9.; 
cards;
A|06/19/2020|3|2
A|06/29/2020|5|3
A|06/30/2020|1|1
A|07/01/2020|4|3
A|07/05/2020|7|1
A|07/15/2020|2|0
A|07/19/2020|3|1
B|05/12/2020|4|4
B|05/24/2020|1|0
B|05/27/2020|3|2
;
run;

PROC SQL noprint;
 create table work.have1 as
 select   t1.Location , t1.DateDate , t1.datedateMinus1Month 
        , t2.DateDate as DateDateCountsQ 
        , t2.Nbr_warnings_N as NcountsQ , t2.Nbr_correct_warnings_T as TcountsQ
 from
   work.have0(drop=Date) t1
 , work.have0            t2
 where     t1.Location = t2.Location
       AND t1.DateDateMinus1Month &amp;lt;= t2.DateDate &amp;lt; t1.DateDate
 order by t1.Location, t1.DateDate  
;
QUIT;

PROC MEANS data=work.have1 SUM noprint NWAY;
 CLASS Location DateDate;
 var NcountsQ TcountsQ;
 output out=have2 sum= / autoname;
run;

data want;
 set have2(DROP=_:);
 R=TcountsQ_Sum/NcountsQ_Sum;
 if Location='A' And DateDate='19JUL2020'd then R_check=(0+1+3+1+3+2)/(2+7+4+1+5+3);
 else R_check=.;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sat, 19 Jun 2021 17:40:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Defining-a-variable-within-a-date-interval/m-p/749041#M80691</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-06-19T17:40:03Z</dc:date>
    </item>
    <item>
      <title>Re: Defining a variable within a date interval</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Defining-a-variable-within-a-date-interval/m-p/749047#M80692</link>
      <description>Thanks Koen, I have a large dataset ...</description>
      <pubDate>Sat, 19 Jun 2021 19:56:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Defining-a-variable-within-a-date-interval/m-p/749047#M80692</guid>
      <dc:creator>Bright</dc:creator>
      <dc:date>2021-06-19T19:56:37Z</dc:date>
    </item>
    <item>
      <title>Re: Defining a variable within a date interval</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Defining-a-variable-within-a-date-interval/m-p/749048#M80693</link>
      <description>&lt;P&gt;What is your definition of "last month".&amp;nbsp; &amp;nbsp;In your example, you apparently mean all the dates &lt;EM&gt;&lt;STRONG&gt;including&lt;/STRONG&gt;&lt;/EM&gt; the &lt;EM&gt;&lt;STRONG&gt;date exactly one month prior&lt;/STRONG&gt;&lt;/EM&gt; (i.e. for 7/19/2020 totals, include 6/19/2020).&amp;nbsp; Is that correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;On the date 1/31/2020 you want not only all of January, but also the last date of December, right?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, then&amp;nbsp;for October 30, 2020 you would want&amp;nbsp; Sep 30-Oct30.&amp;nbsp; &amp;nbsp;But consider October 31, 2020.&amp;nbsp; There is no Sep 31, so would it be Oct 1- Oct31,&amp;nbsp; or Sep 30-Oct31?&amp;nbsp; &amp;nbsp;In such cases, what is your definition of "the date exactly one month prior"?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 Jun 2021 20:14:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Defining-a-variable-within-a-date-interval/m-p/749048#M80693</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-06-19T20:14:22Z</dc:date>
    </item>
    <item>
      <title>Re: Defining a variable within a date interval</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Defining-a-variable-within-a-date-interval/m-p/749049#M80694</link>
      <description>I want 30 days back, excluding the day itself.</description>
      <pubDate>Sat, 19 Jun 2021 20:19:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Defining-a-variable-within-a-date-interval/m-p/749049#M80694</guid>
      <dc:creator>Bright</dc:creator>
      <dc:date>2021-06-19T20:19:43Z</dc:date>
    </item>
    <item>
      <title>Re: Defining a variable within a date interval</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Defining-a-variable-within-a-date-interval/m-p/749050#M80695</link>
      <description>&lt;P&gt;Make 2 arrays, NVALS and TVALS, indexed by date.&amp;nbsp; Set the array bounds to be the lowest and highest expected dates.&amp;nbsp; Then for each new observation, sum the preceding 30 elements of the two arrays, and get the ration of those sums:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);
  set have;
  by location;
  array tvals{%sysevalf("01jan2019"d):%sysevalf("31dec2020"d)} _temporary_;
  array nvals{%sysevalf("01jan2019"d):%sysevalf("31dec2020"d)} _temporary_;
  if first.location=1 then call missing(of tvals{*},of nvals{*},tsum,nsum);
  tvals{date}=t;
  nvals{date}=n;
  do _d=1 to 30;
    tsum=sum(0,tsum,tvals{date-_d});
    nsum=sum(0,nsum,nvals{date-_d});
  end;
  ratio=divide(tsum,nsum);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 Jun 2021 21:04:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Defining-a-variable-within-a-date-interval/m-p/749050#M80695</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-06-19T21:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: Defining a variable within a date interval</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Defining-a-variable-within-a-date-interval/m-p/749069#M80696</link>
      <description>&lt;P&gt;Below should work without consuming too much resources.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input Location $ Date:mmddyy10. N_warnings N_correct_warnings;
  format date date9.;
  datalines;
A 06/19/2020 3 2
A 06/29/2020 5 3
A 06/30/2020 1 1
A 7/01/2020 4 3
A 7/05/2020 7 1
A 07/15/2020 2 0
A 07/19/2020 3 1
A 07/21/2020 0 0
A 07/22/2020 0 0
A 08/01/2020 0 0
A 08/05/2020 0 0
A 08/15/2020 0 0
B 5/12/2020 4 4
B 05/24/2020 1 0
B 05/27/2020 3 2
;

/* &amp;amp;lb: look_back days */
%let lb=30;

data want(drop=_:);
  set have;
  by location date;

  /* arrays to store values of last &amp;amp;lb days */
  array nw  {&amp;amp;lb} 8 _temporary_;
  array ncw {&amp;amp;lb} 8 _temporary_;
  array dt  {&amp;amp;lb} 8 _temporary_;

  if first.location then 
    do;
      call missing(of nw[*], of ncw[*], of dt[*]);
    end;

  else
  if not first.location then
    do;
      /* delete values for array elements not meeting date range condition */
      dt[mod(date,&amp;amp;lb)+1]=date;
      do _i=1 to dim(dt);
        if dt[_i]=date or .&amp;lt;dt[_i]&amp;lt;date-&amp;amp;lb then
          do;
            _ind=mod(dt[_i],&amp;amp;lb)+1;
            call missing(nw[_ind]);
            call missing(ncw[_ind]);
            call missing(dt[_ind]);
          end; 
      end;
    end;
  
  /* create desired sums and ratios */
  nw_sum  =sum(of nw[*]);
  ncw_sum =sum(of ncw[*]);
  ratio=divide(sum(of ncw[*]),sum(of nw[*]));

  /* prep for next row: populate array elements with current row values */
  /* - only at the end to not include into calculations for current row */
  _ind=mod(date,&amp;amp;lb)+1;
  nw[_ind]  =N_warnings;
  ncw[_ind] =N_correct_warnings;
  dt[_ind]  =date;

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1624166781578.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60513iB0C38EBD5C51CDC4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1624166781578.png" alt="Patrick_0-1624166781578.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Jun 2021 05:30:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Defining-a-variable-within-a-date-interval/m-p/749069#M80696</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-06-20T05:30:36Z</dc:date>
    </item>
    <item>
      <title>Re: Defining a variable within a date interval</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Defining-a-variable-within-a-date-interval/m-p/749084#M80697</link>
      <description>&lt;P&gt;A PROC SUMMARY solution (because PROC SUMMARY is my favorite PROC &lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt; ) with a MULTILABEL format. I didn't do the division at the end, but you can add that in yourself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have0;
infile cards delimiter='|' truncover;
input Location $ Date :mmddyy10. Nbr_warnings_N Nbr_correct_warnings_T;
cards;
A|06/19/2020|3|2
A|06/29/2020|5|3
A|06/30/2020|1|1
A|07/01/2020|4|3
A|07/05/2020|7|1
A|07/15/2020|2|0
A|07/19/2020|3|1
B|05/12/2020|4|4
B|05/24/2020|1|0
B|05/27/2020|3|2
;
data _null_;
    set have0 end=eof;
    if _n_=1 then call execute('proc format; value df (multilabel)');
    call execute(cats(date-31,'-',date-1,'=',date));
    if eof then call execute ('; run;');
run;
proc summary data=have0 nway;
    class location;
    class date / mlf;
    var nbr_warnings_n nbr_correct_warnings_t;
    output out=_sums_ sum=/autoname;
    format date df.;
run;
data _sums1_;
    set _sums_;
    ndate=input(left(date),7.);
    format ndate mmddyy10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 Jun 2021 11:45:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Defining-a-variable-within-a-date-interval/m-p/749084#M80697</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-20T11:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: Defining a variable within a date interval</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Defining-a-variable-within-a-date-interval/m-p/749093#M80698</link>
      <description>&lt;P&gt;Assuming there were no tie for DATE .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines truncover;
  input Location $ Date:mmddyy10. N T;
  format date date9.;
  datalines;
A 06/19/2020 3 2
A 06/29/2020 5 3
A 06/30/2020 1 1
A 7/01/2020 4 3
A 7/05/2020 7 1
A 07/15/2020 2 0
A 07/19/2020 3 1
A 07/21/2020 0 0
A 07/22/2020 0 0
A 08/01/2020 0 0
A 08/05/2020 0 0
A 08/15/2020 0 0
B 5/12/2020 4 4
B 05/24/2020 1 0
B 05/27/2020 3 2
;

data want;
 if _n_=1 then do;
  if 0 then set have;
  declare hash h();
  h.definekey('date');
  h.definedata('N','T');
  h.definedone();
 end;
set have;
by Location;
if first.Location then h.clear();
h.add();
sum_n=0;sum_t=0;
do i=date-1 to intnx('month',date,-1,'s') by -1;
  if h.find(key:i)=0 then do;sum_n+n;sum_t+t;end;
end;
want=divide(sum_t,sum_n);
drop i sum_: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 20 Jun 2021 11:52:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Defining-a-variable-within-a-date-interval/m-p/749093#M80698</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-06-20T11:52:01Z</dc:date>
    </item>
  </channel>
</rss>

