<?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: how do I count  difference in dates and a counter on that in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-count-difference-in-dates-and-a-counter-on-that/m-p/613385#M179120</link>
    <description>&lt;P&gt;Hi KurtBremser,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Did you get information you were looking for from my response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any assistance will be highly appriciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
    <pubDate>Sat, 21 Dec 2019 11:12:35 GMT</pubDate>
    <dc:creator>MV04</dc:creator>
    <dc:date>2019-12-21T11:12:35Z</dc:date>
    <item>
      <title>how do I count  difference in dates and a counter on that</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-count-difference-in-dates-and-a-counter-on-that/m-p/612977#M178964</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;I have got a datset as below&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; report_month = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(putn(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(today()),monyy7.));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; report_date = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(putn(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(today()),date9.));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; report_date_beg = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(putn(&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(intnx(month,"&amp;amp;report_date"d,0,b)),date9.));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; report_month : &amp;amp;report_month. report_date : &amp;amp;report_date. report_date_beg :&amp;amp;report_date_beg.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; disp_elg;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;infile&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; datalines &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;dlm&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; = &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;","&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;dsd&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; id $ flag;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;rep_month = symget(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;"report_month"&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1111,1&lt;/P&gt;&lt;P&gt;1211,0&lt;/P&gt;&lt;P&gt;1311,0&lt;/P&gt;&lt;P&gt;1411,1&lt;/P&gt;&lt;P&gt;1511,1&lt;/P&gt;&lt;P&gt;1611,1&lt;/P&gt;&lt;P&gt;1711,1&lt;/P&gt;&lt;P&gt;1811,1&lt;/P&gt;&lt;P&gt;1911,0&lt;/P&gt;&lt;P&gt;2011,0&lt;/P&gt;&lt;P&gt;2111,1&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;run&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;This dataset gives me flag as 1 and 0 per ID and reporting month .&lt;/P&gt;&lt;P&gt;I need to produce a dataset and retain a history for 15 months where the varibales would be like mentioned in the target dataset&lt;/P&gt;&lt;P&gt;if flag is 1 and count of ipqm1 in last 15 month &amp;nbsp;= 0 then code = ipqm1&lt;/P&gt;&lt;P&gt;else if flag is 1 and count of ipqm1&amp;nbsp;&amp;gt; 2 in last 10 months then code = ipqm2&lt;/P&gt;&lt;P&gt;else if flag is 1 and &amp;nbsp;code = ipqm1 and diff_month = 1 then &amp;nbsp;code = ipqm2&lt;/P&gt;&lt;P&gt;else if code = ipqm2 and diff_month = 2 then code = ipqm3&lt;/P&gt;&lt;P&gt;else if code = ipqm3 and diff_month = 6 then code = ipqm1&lt;/P&gt;&lt;P&gt;else if (code = ipqm1 and diff_month &amp;gt; 1) or (code = ipqm2 and diff_month &amp;gt; 2) or (code = ipqm3 and diff_month &amp;gt; 6) then code = ipqm1&lt;/P&gt;&lt;P&gt;else "do nothing"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So basically we need to set the code depending on the differnce in months and count of particular code &amp;nbsp;in that month diff and the data needs to be produced on a monthly basis and get that appended to create the history.&lt;/P&gt;&lt;P&gt;Any&amp;nbsp;support &amp;nbsp;would be highly appriciated &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Target&lt;/P&gt;&lt;P&gt;ID,code,rep_month&lt;/P&gt;&lt;P&gt;1111,ipqm1,dec2018&lt;BR /&gt;1211,ipqm1,dec2018&lt;BR /&gt;1311,ipqm1,dec2018&lt;BR /&gt;1411,ipqm1,dec2018&lt;BR /&gt;1511,ipqm1,dec2018&lt;BR /&gt;1611,ipqm1,dec2018&lt;BR /&gt;1711,ipqm1,dec2018&lt;BR /&gt;1811,ipqm1,dec2018&lt;BR /&gt;1911,ipqm1,dec2018&lt;BR /&gt;2011,ipqm1,dec2018&lt;BR /&gt;2111,ipqm1,dec2018&lt;BR /&gt;2211,ipqm1,Jan2019&lt;BR /&gt;1411,ipqm2,Jan2019&lt;BR /&gt;2311,ipqm1,Jan2019&lt;BR /&gt;1211,ipqm2,Jan2019&lt;BR /&gt;2411,ipqm1,Jan2019&lt;BR /&gt;2511,ipqm1,Jan2019&lt;BR /&gt;2611,ipqm1,Jan2019&lt;BR /&gt;2711,ipqm1,Jan2019&lt;BR /&gt;2811,ipqm1,Jan2019&lt;BR /&gt;2911,ipqm1,Jan2019&lt;BR /&gt;3011,ipqm1,Jan2019&lt;BR /&gt;3111,ipqm1,Feb2019&lt;BR /&gt;3211,ipqm1,Feb2019&lt;BR /&gt;3311,ipqm1,Feb2019&lt;BR /&gt;1311,ipqm3,Feb2019&lt;BR /&gt;3411,ipqm1,Feb2019&lt;BR /&gt;3511,ipqm1,Feb2019&lt;BR /&gt;3611,ipqm1,Feb2019&lt;BR /&gt;3711,ipqm1,Feb2019&lt;BR /&gt;3811,ipqm1,Feb2019&lt;BR /&gt;3911,ipqm1,Feb2019&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2019 10:20:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-count-difference-in-dates-and-a-counter-on-that/m-p/612977#M178964</guid>
      <dc:creator>MV04</dc:creator>
      <dc:date>2019-12-19T10:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: how do I count  difference in dates and a counter on that</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-count-difference-in-dates-and-a-counter-on-that/m-p/612982#M178967</link>
      <description>&lt;P&gt;From where do you derive "count of ipqm1"?&lt;/P&gt;
&lt;P&gt;I also see no variable code in your dataset, but you use it in your "else if" condition.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2019 10:37:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-count-difference-in-dates-and-a-counter-on-that/m-p/612982#M178967</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-19T10:37:29Z</dc:date>
    </item>
    <item>
      <title>Re: how do I count  difference in dates and a counter on that</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-count-difference-in-dates-and-a-counter-on-that/m-p/612983#M178968</link>
      <description>&lt;P&gt;And please post code with the "little running man" button, so we do not need to fix the empty lines (and other "funnies") caused by posting in the main window.&lt;/P&gt;
&lt;P&gt;Post textual data with the {i} button.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2019 10:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-count-difference-in-dates-and-a-counter-on-that/m-p/612983#M178968</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-19T10:38:55Z</dc:date>
    </item>
    <item>
      <title>Re: how do I count  difference in dates and a counter on that</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-count-difference-in-dates-and-a-counter-on-that/m-p/613010#M178982</link>
      <description>&lt;P&gt;Code is what we need to build in the code as what will be the value of code in a given month for a given ID consiering all those if then.&lt;/P&gt;&lt;P&gt;Every month we would receive a dataset as&lt;/P&gt;&lt;P&gt;1111,1&lt;/P&gt;&lt;P&gt;1211,0&lt;/P&gt;&lt;P&gt;1311,0&lt;/P&gt;&lt;P&gt;1411,1&lt;/P&gt;&lt;P&gt;1511,1&lt;/P&gt;&lt;P&gt;1611,1&lt;/P&gt;&lt;P&gt;1711,1&lt;/P&gt;&lt;P&gt;1811,1&lt;/P&gt;&lt;P&gt;1911,0&lt;/P&gt;&lt;P&gt;2011,0&lt;/P&gt;&lt;P&gt;2111,1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and we need to create target dataset as given above&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2019 12:41:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-count-difference-in-dates-and-a-counter-on-that/m-p/613010#M178982</guid>
      <dc:creator>MV04</dc:creator>
      <dc:date>2019-12-19T12:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: how do I count  difference in dates and a counter on that</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-count-difference-in-dates-and-a-counter-on-that/m-p/613017#M178983</link>
      <description>&lt;P&gt;You have answered exactly NONE of my questions. Please read my post again.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2019 12:51:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-count-difference-in-dates-and-a-counter-on-that/m-p/613017#M178983</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-19T12:51:32Z</dc:date>
    </item>
    <item>
      <title>Re: how do I count  difference in dates and a counter on that</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-count-difference-in-dates-and-a-counter-on-that/m-p/613148#M179040</link>
      <description>&lt;P&gt;From where do you derive "count of ipqm1"?&lt;/P&gt;&lt;P&gt;--- we need to derive it in the code as "every time the code =ipqm1 switches from to cde= ipqm2 the value of count is increased to 1so fisrt month say dec2018 when the process started we got&amp;nbsp;account say 1111 as flag "1" and we set the code=ipqm1 then now we need to write a generic program where we need to decide from the next month the value of the code which would depend on the months difference.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also see no variable code in your dataset, but you use it in your "else if" condition&lt;/P&gt;&lt;P&gt;---Like I mentioned above the code needs to be determined in the program itself and hence would populate in the target dataset.&lt;/P&gt;&lt;P&gt;code value (ipqm1,ipqm2,ipqm3) should be unique per id in a givem month.first time the code value is set in the program as ipqm1 and save it as the first dataset in the history.&lt;BR /&gt;here the things need to be considered from second month onwards are:&lt;BR /&gt;1. the number of times(count) the code value changed for an id in last 15 months&lt;BR /&gt;2. for a fresh month check for an id&amp;nbsp; if value of code in the history dataset is ipqm1 and the difference in the months as in from current month to the month when the value of code is ipqm1 is 1 then set code = ipmq2&lt;BR /&gt;&amp;nbsp;&amp;nbsp; otherwise check if the value of code in the history dataset is ipqm2 and the difference of month when the value is ipqm2 from current month is 2 then set code = ipmq3&lt;BR /&gt;&amp;nbsp;&amp;nbsp; oterwise if the value of code in the history dataset is ipqm3 and the difference of month when the value is ipqm3 from current month is 6 then set code = ipmq1&lt;BR /&gt;&amp;nbsp;otherwise&amp;nbsp; if (the value of code in the history dataset is ipqm1 and month differnce as above &amp;gt; 1) or&amp;nbsp; (the value of code in the history dataset is ipqm2 and month differnce as above &amp;gt; 2) or (the value of code in the history dataset is ipqm3 and month differnce as above &amp;gt; 6) then code = ipqm1&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2019 21:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-count-difference-in-dates-and-a-counter-on-that/m-p/613148#M179040</guid>
      <dc:creator>MV04</dc:creator>
      <dc:date>2019-12-19T21:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: how do I count  difference in dates and a counter on that</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-count-difference-in-dates-and-a-counter-on-that/m-p/613385#M179120</link>
      <description>&lt;P&gt;Hi KurtBremser,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Did you get information you were looking for from my response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any assistance will be highly appriciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 21 Dec 2019 11:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-count-difference-in-dates-and-a-counter-on-that/m-p/613385#M179120</guid>
      <dc:creator>MV04</dc:creator>
      <dc:date>2019-12-21T11:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: how do I count  difference in dates and a counter on that</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-do-I-count-difference-in-dates-and-a-counter-on-that/m-p/616150#M180334</link>
      <description>&lt;P&gt;What will be the first code set at the first entry for a given id, depending on flag?&lt;/P&gt;
&lt;P&gt;What is the formula for the next entry encountered?&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2020 08:52:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-do-I-count-difference-in-dates-and-a-counter-on-that/m-p/616150#M180334</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-09T08:52:57Z</dc:date>
    </item>
  </channel>
</rss>

