<?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 Diference Date (MONTH) by ID in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Diference-Date-MONTH-by-ID/m-p/749643#M80700</link>
    <description>&lt;P&gt;Hello good morning, I could not find the way to do the following, I have an ID and a date of a certain event. I must add the difference in months of an event with the following one by ID.&lt;/P&gt;&lt;P&gt;Example in excel in the photograph.&lt;/P&gt;&lt;P&gt;someone who can help me, Greetings.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Andres_Fuentes1_0-1624382354559.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60630i4AD7E839B30A597F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Andres_Fuentes1_0-1624382354559.png" alt="Andres_Fuentes1_0-1624382354559.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Jun 2021 17:19:34 GMT</pubDate>
    <dc:creator>Andres_Fuentes1</dc:creator>
    <dc:date>2021-06-22T17:19:34Z</dc:date>
    <item>
      <title>Diference Date (MONTH) by ID</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Diference-Date-MONTH-by-ID/m-p/749643#M80700</link>
      <description>&lt;P&gt;Hello good morning, I could not find the way to do the following, I have an ID and a date of a certain event. I must add the difference in months of an event with the following one by ID.&lt;/P&gt;&lt;P&gt;Example in excel in the photograph.&lt;/P&gt;&lt;P&gt;someone who can help me, Greetings.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Andres_Fuentes1_0-1624382354559.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60630i4AD7E839B30A597F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Andres_Fuentes1_0-1624382354559.png" alt="Andres_Fuentes1_0-1624382354559.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 17:19:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Diference-Date-MONTH-by-ID/m-p/749643#M80700</guid>
      <dc:creator>Andres_Fuentes1</dc:creator>
      <dc:date>2021-06-22T17:19:34Z</dc:date>
    </item>
    <item>
      <title>Re: Diference Date (MONTH) by ID</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Diference-Date-MONTH-by-ID/m-p/749652#M80701</link>
      <description>&lt;P&gt;And so what is the desired result? Do you want 9 for ID = 1 and 12 for ID = 2 and 12 for ID=3?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is your date variable a character variable in SAS or a numeric variable in SAS? What does PROC CONTENTS say?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FYI, please do not provide data as screen captures from Excel. The preferred method to provide data is:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_blank" rel="noopener"&gt;https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 18:05:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Diference-Date-MONTH-by-ID/m-p/749652#M80701</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-06-22T18:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Diference Date (MONTH) by ID</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Diference-Date-MONTH-by-ID/m-p/749656#M80702</link>
      <description>&lt;P&gt;That's Excel, not SAS data shown. In the future please show the SAS version. &lt;STRONG&gt;I'm assuming you have your data imported and that your date are SAS dates&lt;/STRONG&gt;, eg numeric with a date format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by ID;
run;

data want;
set have;

by ID;

prev_date = lag(date);

if not first.id then n_month = intck('month', date, prev_date, 'C');

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You may need to play with the INTCK() function to get the exact numbers you want but this gives you an idea of how to do it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/386950"&gt;@Andres_Fuentes1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello good morning, I could not find the way to do the following, I have an ID and a date of a certain event. I must add the difference in months of an event with the following one by ID.&lt;/P&gt;
&lt;P&gt;Example in excel in the photograph.&lt;/P&gt;
&lt;P&gt;someone who can help me, Greetings.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Andres_Fuentes1_0-1624382354559.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/60630i4AD7E839B30A597F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Andres_Fuentes1_0-1624382354559.png" alt="Andres_Fuentes1_0-1624382354559.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 17:48:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Diference-Date-MONTH-by-ID/m-p/749656#M80702</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-06-22T17:48:15Z</dc:date>
    </item>
    <item>
      <title>Re: Diference Date (MONTH) by ID</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Diference-Date-MONTH-by-ID/m-p/749685#M80703</link>
      <description>Please try this:&lt;BR /&gt;proc sort data=your_data; by ID date;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data results;&lt;BR /&gt;set your_data;&lt;BR /&gt;by ID date;;&lt;BR /&gt;retain pre_Date .;&lt;BR /&gt;if first.ID then do;&lt;BR /&gt;n_month=.;&lt;BR /&gt;pre_Date=date;&lt;BR /&gt;end;&lt;BR /&gt;else do;&lt;BR /&gt;n_month=intck('month', pre_Date, date, 'C');&lt;BR /&gt;pre_Date=date;&lt;BR /&gt;end;&lt;BR /&gt;drop pre_Date;&lt;BR /&gt;run;&lt;BR /&gt;</description>
      <pubDate>Tue, 22 Jun 2021 19:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Diference-Date-MONTH-by-ID/m-p/749685#M80703</guid>
      <dc:creator>Jerrya00</dc:creator>
      <dc:date>2021-06-22T19:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Diference Date (MONTH) by ID</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Diference-Date-MONTH-by-ID/m-p/749699#M80704</link>
      <description>&lt;P&gt;Nice, Thanks you.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Jun 2021 20:08:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Diference-Date-MONTH-by-ID/m-p/749699#M80704</guid>
      <dc:creator>Andres_Fuentes1</dc:creator>
      <dc:date>2021-06-22T20:08:20Z</dc:date>
    </item>
  </channel>
</rss>

