<?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: Issues with Arrays and Dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897737#M354803</link>
    <description>&lt;P&gt;Why would you make an array with only one variable in it?&amp;nbsp; Why not just reference the variable directly instead of going to the trouble of accessing it indirectly via an index into an array with only one element?&lt;/P&gt;</description>
    <pubDate>Sun, 08 Oct 2023 23:59:17 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-10-08T23:59:17Z</dc:date>
    <item>
      <title>Issues with Arrays and Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897736#M354802</link>
      <description>&lt;P&gt;Hello I am trying to compare 2 dates using arrays and create a counter when the dates are within 30 days of each other. It does not seem to work. Attached is my SAS&amp;nbsp; dataset and below is my code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;data master_utp_3;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; set sas.master_utp2;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; by luid;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if first.luid then do;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; *-- Array for TRANS DATE to compare against impressions and clicks for time difference --*;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; &amp;nbsp; array trans_dt {*} trans_event_dt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; *-- Array for DISPLAY DATE to compare against impressions and clicks for time difference --*;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; &amp;nbsp; array dis_dt [*] display_imps_event_dt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; end;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; *-- Checking to ensure the impression or click was 30-days prior to the transaction --*;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; do i=1 to dim(trans_dt) until(_check_pre_trans_display&amp;gt;0);&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; _check_pre_trans_display = (intck('day',display_imps_event_dt,trans_dt(i)))&amp;lt;=30&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; and&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; (intck('day',display_imps_event_dt,trans_dt(i)))&amp;gt;=0;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; end;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; if _check_pre_trans_display&amp;gt;=1 then do;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; pre_display_imps+1;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN&gt; end;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;run;&lt;/DIV&gt;</description>
      <pubDate>Sun, 08 Oct 2023 23:41:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897736#M354802</guid>
      <dc:creator>Kaushansky</dc:creator>
      <dc:date>2023-10-08T23:41:10Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with Arrays and Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897737#M354803</link>
      <description>&lt;P&gt;Why would you make an array with only one variable in it?&amp;nbsp; Why not just reference the variable directly instead of going to the trouble of accessing it indirectly via an index into an array with only one element?&lt;/P&gt;</description>
      <pubDate>Sun, 08 Oct 2023 23:59:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897737#M354803</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-08T23:59:17Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with Arrays and Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897739#M354804</link>
      <description>&lt;P&gt;&lt;SPAN&gt;The &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/casmopt/casmopt_clp_syntax04.htm#:~:text=The%20ARRAY%20statement%20is%20used,by%20using%20the%20FOREACH%20statement." target="_self"&gt;ARRAY statement&lt;/A&gt; is used to associate a&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=" aa-argument"&gt;name&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;with a list of&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=" aa-argument"&gt;variables&lt;/SPAN&gt;&lt;SPAN&gt;.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;An array statement requires the data to be on a single row in multiple variables. That's not your data structure and though using an array statement won't work.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1696809789569.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/88713i8EC5FE6B87538AAE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1696809789569.png" alt="Patrick_0-1696809789569.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given your data structure can you please show how the desired result should look like?&lt;/P&gt;
&lt;P&gt;For example for row 10 would you want a count of any trans_event_date that's within 30 days of 2022-04-04? Or something else?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 00:08:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897739#M354804</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-10-09T00:08:34Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with Arrays and Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897746#M354807</link>
      <description>&lt;P&gt;Yes, exactly row 10 (2022-04-04) should be within 30 days of any of the column&amp;nbsp;trans_event_dt (dates). Doesn't an Array capture all of the row instances in a set for comparison?&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 01:37:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897746#M354807</guid>
      <dc:creator>Kaushansky</dc:creator>
      <dc:date>2023-10-09T01:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with Arrays and Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897747#M354808</link>
      <description>&lt;P&gt;I cannot reference it directly, I need column&amp;nbsp;display_imps_event_dt to check whether it is within 30 days of any of the values in column&amp;nbsp;trans_event_dt and the rows are different. This is just one case (ID), other IDs will have different values and rows, etc.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 01:40:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897747#M354808</guid>
      <dc:creator>Kaushansky</dc:creator>
      <dc:date>2023-10-09T01:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with Arrays and Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897748#M354809</link>
      <description>&lt;P&gt;Arrays have nothing to do with OBSERVATIONS.&amp;nbsp; &amp;nbsp;They are used to reference multiple variables of the observation you are currently processing.&amp;nbsp; Do you have multiple variables in your dataset?&amp;nbsp; or do you want to transpose the data from multiple observations into multiple variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I cannot see your data since you posted a FILE instead of CODE.&amp;nbsp; Also please provide a verbal description of what you have as I am not sure what an "impression" and a "click" are.&amp;nbsp; Nor how you have coded those in your dataset.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 02:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897748#M354809</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-09T02:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with Arrays and Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897749#M354810</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;create a counter when the dates are within 30 days of each other&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;Counter of what?&amp;nbsp; The number of "trans" within 30 days of the "imp"?&amp;nbsp; Or the other way around?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Is that 30 days before?&amp;nbsp; 30 days after?&amp;nbsp; Is it 15 before and 15 after? &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What about the same day?&amp;nbsp; &amp;nbsp;29 days before plus today? 15 before and 14 after?&amp;nbsp; 14 before and 15 after? 29 days after plus today?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Or do you want to count DAYS?&amp;nbsp; Perhaps: How many of the 30 preceding&amp;nbsp;days had the other type of activity?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 03:02:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897749#M354810</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-09T03:02:30Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with Arrays and Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897750#M354811</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/373742"&gt;@Kaushansky&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Yes, exactly row 10 (2022-04-04) should be within 30 days of any of the column&amp;nbsp;trans_event_dt (dates). Doesn't an Array capture all of the row instances in a set for comparison?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;An array works within a single row (observation) for multiple variables but not over multiple observations for a single variable.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You haven't provided the desired result which is why below code provides options based on guessing.&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.have;
  infile datalines dsd truncover;
  input luid:BEST12. trans_event_dt:YYMMDD10. display_imps_event_dt:YYMMDD10.;
  format luid BEST12. trans_event_dt YYMMDD10. display_imps_event_dt YYMMDD10.;
datalines4;
1019715261,2023-01-20,
1019715261,2023-01-24,
1019715261,2023-02-03,
1019715261,2023-03-01,
1019715261,2023-03-25,
1019715261,2023-03-25,
1019715261,2023-03-25,
1019715261,2023-03-25,
1019715261,2023-03-29,
1019715261,,2022-04-04
1019715261,,2022-08-13
1019715261,,2022-09-01
1019715261,,2022-09-27
1019715261,,2022-09-27
1019715261,,2023-02-13
1019715261,,2023-02-13
1019715261,,2023-02-13
1019715261,,2023-02-13
1019715261,,2023-02-13
1019715261,,2023-02-13
1019715261,,2023-02-13
1019715261,,2023-02-13
1019715261,,2023-02-13
1019715261,,2023-02-13
1019715261,,2023-02-13
1019715261,,2023-02-13
1019715261,,2023-02-13
1019715261,,2023-02-13
1019715261,,2023-02-13
1019715261,,2023-03-03
1019715261,,2023-03-11
1019715261,,2023-03-11
1019715261,,2023-03-11
1019715261,,2023-03-11
1019715261,,2023-03-11
1019715261,,2023-03-13
1019715261,,2023-03-17
1019715261,,2023-03-17
1019715261,,2023-03-18
1019715261,,2023-03-18
1019715261,,2023-03-18
1019715261,,2023-03-18
1019715261,,2023-03-18
1019715261,,2023-03-18
1019715261,,2023-03-21
1019715261,,2023-03-25
1019715261,,2023-03-25
1019715261,,2023-03-25
1019715261,,2023-03-25
1019715261,,2023-03-25
1019715261,,
1019715261,,
;;;;

data work.want;
  if _n_=1 then
    do;
      dcl hash h1(dataset:'work.have(where=(not missing(trans_event_dt)))', multidata:'y');
      h1.defineKey('luid');
      h1.defineData('trans_event_dt');
      h1.defineDone();
    end;

  set have;
  by luid;

  if first.luid then count1=0;
  count2=0;
  h1.reset_dup();
  do while(h1.do_over() eq 0);
    if trans_event_dt-30 &amp;lt;= display_imps_event_dt &amp;lt;= trans_event_dt then
      do;
        count1+1;
        count2=sum(count2,1);
      end;
  end;

  if first.luid then count3=0;
  count4=0;
  h1.reset_dup();
  do while(h1.do_over() eq 0);
    if trans_event_dt-30 &amp;lt;= display_imps_event_dt &amp;lt;= trans_event_dt then
      do;
        count3+1;
        count4=sum(count4,1);
        leave;
      end;
  end;

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;</description>
      <pubDate>Mon, 09 Oct 2023 03:09:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897750#M354811</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-10-09T03:09:42Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with Arrays and Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897751#M354812</link>
      <description>&lt;P&gt;So I did download that dataset and look at it.&amp;nbsp; You appear to have two datasets mashed into one as no observations have a value in both date fields.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So it is probably easier to understand what you are trying to do it we separate them.&amp;nbsp; Let's use easier to type variable names and dataset names also.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So you have TRANS (transactions or orders perhaps) dataset and an IMPRESSIONS (site visits?) dataset that each have an ID variable and a DATE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data trans;
  input id :$12. date :yymmdd. ;
  format date yymmdd10.;
cards;
1019715261 2023-01-20 
1019715261 2023-01-24 
1019715261 2023-02-03 
1019715261 2023-03-01 
1019715261 2023-03-25 
1019715261 2023-03-25  
1019715261 2023-03-25 
1019715261 2023-03-25 
1019715261 2023-03-29 

data impressions;
  input id :$12. date :yymmdd.;
  format date yymmdd10.;
cards;
1019715261 2022-04-04
1019715261 2022-08-13
1019715261 2022-09-01
1019715261 2022-09-27
1019715261 2022-09-27
1019715261 2023-02-13
1019715261 2023-02-13
1019715261 2023-02-13
1019715261 2023-02-13
1019715261 2023-02-13
1019715261 2023-02-13
1019715261 2023-02-13
1019715261 2023-02-13
1019715261 2023-02-13
1019715261 2023-02-13
1019715261 2023-02-13
1019715261 2023-02-13
1019715261 2023-02-13
1019715261 2023-02-13
1019715261 2023-02-13
1019715261 2023-03-03
1019715261 2023-03-11
1019715261 2023-03-11
1019715261 2023-03-11
1019715261 2023-03-11
1019715261 2023-03-11
1019715261 2023-03-13
1019715261 2023-03-17
1019715261 2023-03-17
1019715261 2023-03-18
1019715261 2023-03-18
1019715261 2023-03-18
1019715261 2023-03-18
1019715261 2023-03-18
1019715261 2023-03-18
1019715261 2023-03-21
1019715261 2023-03-25
1019715261 2023-03-25
1019715261 2023-03-25
1019715261 2023-03-25
1019715261 2023-03-25
;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So SQL is a good language for describing set operations like number of x within some criteria.&lt;/P&gt;
&lt;P&gt;Here is a query to count the total number of IMPRESSIONS and the number of distinct days they occur on that fall within the date range that starts 30 before the TRANS date and includes the TRANS date.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table count1 as
  select a.id,a.date,count(b.id) as n_imps,count(distinct b.date) as imp_days
  from trans a
    left join impressions b
    on a.id = b.id and a.date-30 &amp;lt;= b.date &amp;lt;= a.date
  group by 1,2
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;Obs        id              date    n_imps    imp_days

 1     1019715261    2023-01-20       0          0
 2     1019715261    2023-01-24       0          0
 3     1019715261    2023-02-03       0          0
 4     1019715261    2023-03-01      15          1
 5     1019715261    2023-03-25      84          7
 6     1019715261    2023-03-29      21          7
&lt;/PRE&gt;
&lt;P&gt;That is getting confused by the repetitions of TRANS records on the same DATE.&amp;nbsp; Let's collapse those first.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table count1 as
  select a.id,a.date,a.n_trans,count(b.id) as n_imps,count(distinct b.date) as imp_days
  from (select id,date,count(*) as n_trans from trans group by id,date) a
    left join impressions b
    on a.id = b.id and a.date-30 &amp;lt;= b.date &amp;lt;= a.date
  group by 1,2,3
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs        id              date    n_trans    n_imps    imp_days

 1     1019715261    2023-01-20       1          0          0
 2     1019715261    2023-01-24       1          0          0
 3     1019715261    2023-02-03       1          0          0
 4     1019715261    2023-03-01       1         15          1
 5     1019715261    2023-03-25       4         21          7
 6     1019715261    2023-03-29       1         21          7
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is that something like what you are looking for?&lt;/P&gt;
&lt;P&gt;Is your data small enough that the SQL query runs quickly enough?&amp;nbsp; or do you still need help in crafting something using data step logic that might run faster?&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 04:06:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897751#M354812</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-09T04:06:24Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with Arrays and Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897825#M354850</link>
      <description>&lt;P&gt;Not exactly. The SQL is good to compare when the columns of dates are aligned, but....The dataset by design, has one set of dates (columns) in a separate column from another and does not align by row. Is there a way, perhaps using the LAG() function or a new function HASH() to store column (trans_event_dt) and (display_imps_event_dt) then compare the ensure that column (display_imps_event_dt) occurs 30-days prior to (trans_event_dt).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 15:01:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897825#M354850</guid>
      <dc:creator>Kaushansky</dc:creator>
      <dc:date>2023-10-09T15:01:22Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with Arrays and Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897826#M354851</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/373742"&gt;@Kaushansky&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Not exactly. The SQL is good to compare when the columns of dates are aligned, but....The dataset by design, has one set of dates (columns) in a separate column from another and does not align by row. Is there a way, perhaps using the LAG() function or a new function HASH() to store column (trans_event_dt) and (display_imps_event_dt) then compare the ensure that column (display_imps_event_dt) occurs 30-days prior to (trans_event_dt).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To use the SQL query with a single dataset as input then just use the dataset as the inputs for both halves of the join, with appropriate renaming for variable references and filtering out the missing values.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 15:04:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897826#M354851</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-09T15:04:20Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with Arrays and Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897829#M354852</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;
&lt;P&gt;I think the HASH structure works, albeit I am not familiar with it as it is new. Could you explain what it is actually doing?&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2023 15:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897829#M354852</guid>
      <dc:creator>Kaushansky</dc:creator>
      <dc:date>2023-10-09T15:11:22Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with Arrays and Dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897835#M354856</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/373742"&gt;@Kaushansky&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Not exactly. The SQL is good to compare when the columns of dates are aligned, but....The dataset by design, has one set of dates (columns) in a separate column from another and does not align by row. Is there a way, perhaps using the LAG() function or a new function HASH() to store column (trans_event_dt) and (display_imps_event_dt) then compare the ensure that column (display_imps_event_dt) occurs 30-days prior to (trans_event_dt).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You can brute force it with a temporary array that uses the DATE as the index.&lt;/P&gt;
&lt;P&gt;Just make the array large enough for the range of dates you expect (or pre calculate the range you have).&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id :$12. trans :yymmdd. imps :yymmdd.;
  format trans imps yymmdd10.;
cards;
1019715261 2023-01-20 .
1019715261 2023-01-24 .
1019715261 2023-02-03 .
1019715261 2023-03-01 .
1019715261 2023-03-25 .
1019715261 2023-03-25 .
1019715261 2023-03-25 .
1019715261 2023-03-25 .
1019715261 2023-03-29 .
1019715261 . 2022-04-04
1019715261 . 2022-08-13
1019715261 . 2022-09-01
1019715261 . 2022-09-27
1019715261 . 2022-09-27
1019715261 . 2023-02-13
1019715261 . 2023-02-13
1019715261 . 2023-02-13
1019715261 . 2023-02-13
1019715261 . 2023-02-13
1019715261 . 2023-02-13
1019715261 . 2023-02-13
1019715261 . 2023-02-13
1019715261 . 2023-02-13
1019715261 . 2023-02-13
1019715261 . 2023-02-13
1019715261 . 2023-02-13
1019715261 . 2023-02-13
1019715261 . 2023-02-13
1019715261 . 2023-02-13
1019715261 . 2023-03-03
1019715261 . 2023-03-11
1019715261 . 2023-03-11
1019715261 . 2023-03-11
1019715261 . 2023-03-11
1019715261 . 2023-03-11
1019715261 . 2023-03-13
1019715261 . 2023-03-17
1019715261 . 2023-03-17
1019715261 . 2023-03-18
1019715261 . 2023-03-18
1019715261 . 2023-03-18
1019715261 . 2023-03-18
1019715261 . 2023-03-18
1019715261 . 2023-03-18
1019715261 . 2023-03-21
1019715261 . 2023-03-25
1019715261 . 2023-03-25
1019715261 . 2023-03-25
1019715261 . 2023-03-25
1019715261 . 2023-03-25
1019715261 . .
1019715261 . .
;

%let minday=%sysfunc(mdy(1,1,2022));
%let maxday=%sysfunc(mdy(12,31,2023));

data want;
  array tranday [&amp;amp;minday:&amp;amp;maxday] _temporary_;
  array impday [&amp;amp;minday:&amp;amp;maxday] _temporary_;
  call missing(of tranday[*] impday[*]);
  do until(last.id);
    set have ;
    by id;
    min_trans=min(min_trans,trans);
    max_trans=max(max_trans,trans);
    if trans then tranday[trans]+1;
    if imps then impday[imps]+1;
  end;
  do date=min_trans to max_trans ;
    n_trans=tranday[date];
    n_imps=0;
    n_impdays=0;
    if n_trans then do date2=date-30 to date;
      n_imps + impday[date2];
      n_impdays + (impday[date2]&amp;gt;0);
    end;
    if n_trans then output;
  end;
  format date yymmdd10.;
  keep id date n_: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result&lt;/P&gt;
&lt;PRE&gt;Obs        id              date    n_trans    n_imps    n_impdays

 1     1019715261    2023-01-20       1          0          0
 2     1019715261    2023-01-24       1          0          0
 3     1019715261    2023-02-03       1          0          0
 4     1019715261    2023-03-01       1         15          1
 5     1019715261    2023-03-25       4         21          7
 6     1019715261    2023-03-29       1         21          7
&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Oct 2023 16:08:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Issues-with-Arrays-and-Dates/m-p/897835#M354856</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-10-09T16:08:16Z</dc:date>
    </item>
  </channel>
</rss>

