<?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: Summation of comparison of dates within Rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/648884#M194466</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/153171"&gt;@Albert0&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you sure whether&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD&gt;01/11/20&lt;/TD&gt;
&lt;TD&gt;50&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD&gt;01/01/21&lt;/TD&gt;
&lt;TD&gt;60&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the count&amp;nbsp; of monthly intervals between 01/11/20 and 01/01/21 is within 3 months? i.e. considering it is formatted as MMDDYY&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 19 May 2020 15:41:23 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2020-05-19T15:41:23Z</dc:date>
    <item>
      <title>Summation of comparison of dates within Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/648859#M194454</link>
      <description>&lt;P&gt;Hi Guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have some sample data below and wanted to calculate the SUM_TAG column.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;KEY&lt;/TD&gt;&lt;TD&gt;DATE&lt;/TD&gt;&lt;TD&gt;VALUE&lt;/TD&gt;&lt;TD&gt;SUM_TAG&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;01/01/20&lt;/TD&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;01/02/20&lt;/TD&gt;&lt;TD&gt;20&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;01/04/20&lt;/TD&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;01/07/20&lt;/TD&gt;&lt;TD&gt;40&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;01/11/20&lt;/TD&gt;&lt;TD&gt;50&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;01/01/21&lt;/TD&gt;&lt;TD&gt;60&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;01/07/21&lt;/TD&gt;&lt;TD&gt;70&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;01/08/20&lt;/TD&gt;&lt;TD&gt;80&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;01/10/20&lt;/TD&gt;&lt;TD&gt;90&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;10&lt;/TD&gt;&lt;TD&gt;B&lt;/TD&gt;&lt;TD&gt;01/02/21&lt;/TD&gt;&lt;TD&gt;100&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The logic on how I populate the column SUM_TAG is first is to group it by column KEY. Once grouped, the DATE value in each row should be within 3 months of the above row.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, the SUM_TAG of ID 1 and 2 is 1 because the DATE of ID 1 and 2 is within 3 months which is&amp;nbsp;01/01/20 and&amp;nbsp;01/02/20. Also ID 3 is has a SUM_TAG of 1 because the DATE value is 01/04/20&amp;nbsp; which is within 3 months of ID 2 which has the DATE&amp;nbsp;01/02/20.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Starting from ID 5 the SUM_TAG is 2 because the DATE value of the record is more than 3 months to the DATE value of ID 4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using first., last. and lag function to compare the rows but the result is as desired.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;Albert0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 14:43:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/648859#M194454</guid>
      <dc:creator>Albert0</dc:creator>
      <dc:date>2020-05-19T14:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: Summation of comparison of dates within Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/648862#M194456</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I tried using first., last. and lag function to compare the rows but the result is as desired.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;Show us what you tried. Explain why the result was not acceptable.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;For future reference, do not provide data as screen captures. It is much better to provide data in a form we can work with, as described here:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank" rel="noopener"&gt;How to create a data step version of your data AKA generate sample data for forums&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 14:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/648862#M194456</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-05-19T14:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: Summation of comparison of dates within Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/648873#M194462</link>
      <description>&lt;P&gt;If you are going to use dates without 4 digits you really need to tell us what format you are using if you are not providing actual SAS data step code to describe the data.&lt;/P&gt;
&lt;P&gt;For example 01/02/20 could be:&amp;nbsp;&amp;nbsp; 02 Jan 2020, 01 Feb 2020 or 20 Feb 2001. Depending on which of these the values are actually using telling "within 3 months" is pretty hard.&lt;/P&gt;
&lt;P&gt;AND depending on the system YEARCUTOFF value in effect might be entirely different years.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Moral of the story: It is a bad idea (unless your boss insists) to ever use dates without 4 digits for display.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Additionally from a picture we cannot tell if you actually have SAS date values, which will be needed to do comparisons like "within 3 months" or a character value. If your date is a character variable then your solution will involve creating a SAS date value.&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 15:09:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/648873#M194462</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-19T15:09:39Z</dc:date>
    </item>
    <item>
      <title>Re: Summation of comparison of dates within Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/648884#M194466</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/153171"&gt;@Albert0&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you sure whether&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD&gt;01/11/20&lt;/TD&gt;
&lt;TD&gt;50&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD&gt;01/01/21&lt;/TD&gt;
&lt;TD&gt;60&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the count&amp;nbsp; of monthly intervals between 01/11/20 and 01/01/21 is within 3 months? i.e. considering it is formatted as MMDDYY&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 15:41:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/648884#M194466</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-19T15:41:23Z</dc:date>
    </item>
    <item>
      <title>Re: Summation of comparison of dates within Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/648891#M194469</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/153171"&gt;@Albert0&lt;/a&gt;&amp;nbsp;This code produces the sum_tag values you had in your table&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	length id 4
		key $1
		date 8
		value 4
		;
	input ID KEY $ DATE :ddmmyy. VALUE;
	format date ddmmyy.;
datalines; 
1 A 01/01/20 10
2 A 01/02/20 20
3 A 01/04/20 30
4 A 01/07/20 40
5 A 01/11/20 50
6 A 01/01/21 60
7 A 01/07/21 70
8 B 01/08/20 80
9 B 01/10/20 90
10 B 01/02/21 100
;
run;

proc sort data=have;
	by key id;
run;

data want(drop= prev_dt diff);
	length prev_dt 8;

	set have;
	by key id;

	/* Reset sum_tag to 1 */
	if ((_n_=1) OR (lag(key) NE key)) then sum_tag=1;

	prev_dt = lag(date); /* Find Previous date */&lt;BR /&gt;
	diff= intck('month',prev_dt,date);

	/* Increase sum_tag whenever diff exceeds 3 */
	if (diff &amp;gt; 3) then  
		sum_tag + 1;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;Ahmed&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 15:51:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/648891#M194469</guid>
      <dc:creator>AhmedAl_Attar</dc:creator>
      <dc:date>2020-05-19T15:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: Summation of comparison of dates within Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/648988#M194511</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/153171"&gt;@Albert0&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you sure whether&lt;/P&gt;
&lt;TABLE border="0" cellspacing="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;5&lt;/TD&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD&gt;01/11/20&lt;/TD&gt;
&lt;TD&gt;50&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;6&lt;/TD&gt;
&lt;TD&gt;A&lt;/TD&gt;
&lt;TD&gt;01/01/21&lt;/TD&gt;
&lt;TD&gt;60&lt;/TD&gt;
&lt;TD&gt;2&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the count&amp;nbsp; of monthly intervals between 01/11/20 and 01/01/21 is within 3 months? i.e. considering it is formatted as MMDDYY&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I suspect the data is actually YYMMDD. But that is why I brought to point up about 4 digit years earlier.&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 19:23:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/648988#M194511</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-05-19T19:23:56Z</dc:date>
    </item>
    <item>
      <title>Re: Summation of comparison of dates within Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/649006#M194515</link>
      <description>&lt;P&gt;Sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; my apologies, I overlooked your previous post. Yes, that's my concern too.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 May 2020 20:01:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/649006#M194515</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-05-19T20:01:46Z</dc:date>
    </item>
    <item>
      <title>Re: Summation of comparison of dates within Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/649158#M194587</link>
      <description>&lt;P&gt;Something like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  by Key ID;
  if intck('month',lag(date),date)&amp;gt;3 then
    sum_tag+1;
  if first.Key then
    sum_tag=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 20 May 2020 10:54:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/649158#M194587</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-05-20T10:54:18Z</dc:date>
    </item>
    <item>
      <title>Re: Summation of comparison of dates within Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/650079#M194933</link>
      <description>Sorry the format is DD/MM/YY</description>
      <pubDate>Sat, 23 May 2020 12:30:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/650079#M194933</guid>
      <dc:creator>Albert0</dc:creator>
      <dc:date>2020-05-23T12:30:49Z</dc:date>
    </item>
    <item>
      <title>Re: Summation of comparison of dates within Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/650080#M194934</link>
      <description>Sorry to trouble you. The format I have in my example is in DD/MM/YY.</description>
      <pubDate>Sat, 23 May 2020 12:31:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/650080#M194934</guid>
      <dc:creator>Albert0</dc:creator>
      <dc:date>2020-05-23T12:31:36Z</dc:date>
    </item>
    <item>
      <title>Re: Summation of comparison of dates within Rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/650081#M194935</link>
      <description>Thank you. Your suggestion works as I wanted..</description>
      <pubDate>Sat, 23 May 2020 12:32:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Summation-of-comparison-of-dates-within-Rows/m-p/650081#M194935</guid>
      <dc:creator>Albert0</dc:creator>
      <dc:date>2020-05-23T12:32:12Z</dc:date>
    </item>
  </channel>
</rss>

