<?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 create a variable that returns gaps in panel data? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-variable-that-returns-gaps-in-panel-data/m-p/729269#M226927</link>
    <description>&lt;P&gt;In the absence of proc timeseries, here is a two-data-step solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data gaps (keep=loan_id yyyymm gap ngaps_this_loan);
  set have (keep=loan_id ) end=end_of_have;
  by loan_id;
  merge have have (firstobs=2 keep=x_loan_age rename=(x_loan_age=nxt_age));

  if first.loan_id then ngaps_this_loan=0;  /*N of gaps for this loan */
  gap=nxt_age-x_loan_age;
  if last.loan_id=0 and gap^=1;
  ngaps_this_loan+1;

  retain max_ngap;  /*Track the maximum number of gaps */
  max_ngap=max(max_ngap,ngaps_this_loan);
  if dif(max_ngap) then call symput('max_ngap',cats(max_ngap));
run;

data want (keep=loan_id gapstart: gapsize:);
  do g=1 by 1 until (last.loan_id);
    set gaps;
    by loan_id;
    array gapstart{&amp;amp;max_ngap};
    array gapsize{&amp;amp;max_ngap};
    gapstart{g}=yyyymm;
    gapsize{g}=gap;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 26 Mar 2021 03:08:35 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2021-03-26T03:08:35Z</dc:date>
    <item>
      <title>How do I create a variable that returns gaps in panel data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-variable-that-returns-gaps-in-panel-data/m-p/729209#M226900</link>
      <description>&lt;P&gt;I am not exactly sure how to describe this, but I have a panel dataset of loans that gives the loan age by month. Occasionally there are gaps, and I want to record in a new variable the total number of gaps. For instance, see the data below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nbs98495_0-1616700402463.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/56511i0F632E67ADD0B455/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nbs98495_0-1616700402463.png" alt="nbs98495_0-1616700402463.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to save, by loan_id, the different gaps in x_loan_age. So I would like to save that there is a 38 month starting in 200508 (YYYYMM variable), a 9 month gap starting in 200801, and a 15 month gap starting in 200810.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ideally I would create variables called "GAP1", "GAP1START", "GAP2", "GAP2START", "GAP3", and "GAP3START".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The output would then be:&lt;/P&gt;&lt;P&gt;38, 200508, 9, 200801, 15, 200810.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There are tons of loans in this dataset, so I want to do this by each loan_id.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically, this is a dataset of when people didn't pay their loans and the gaps are when the person actually paid. I am trying to discern when they were paying among these missed payments.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If this can't be handled by sas, alternatively I would just like to count the cumulative "gap" space. So for the above loan, returning a variable called "GAPS" that = 38+9+15.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached is a SAS dataset of the data I pasted. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Mar 2021 19:34:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-variable-that-returns-gaps-in-panel-data/m-p/729209#M226900</guid>
      <dc:creator>nbs98495</dc:creator>
      <dc:date>2021-03-25T19:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a variable that returns gaps in panel data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-variable-that-returns-gaps-in-panel-data/m-p/729216#M226905</link>
      <description>&lt;P&gt;Is this true timeseries data and do you have SAS/ETS (for PROC TIMESERIES)?&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Using-the-TIMESERIES-procedure-to-check-the-continuity-of-your/ta-p/714678" target="_self"&gt; See this article&lt;/A&gt; from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271728"&gt;@gsvolba&lt;/a&gt;&amp;nbsp;for some ideas and a SAS macro that may help.&lt;/P&gt;</description>
      <pubDate>Thu, 25 Mar 2021 19:56:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-variable-that-returns-gaps-in-panel-data/m-p/729216#M226905</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2021-03-25T19:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a variable that returns gaps in panel data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-variable-that-returns-gaps-in-panel-data/m-p/729269#M226927</link>
      <description>&lt;P&gt;In the absence of proc timeseries, here is a two-data-step solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data gaps (keep=loan_id yyyymm gap ngaps_this_loan);
  set have (keep=loan_id ) end=end_of_have;
  by loan_id;
  merge have have (firstobs=2 keep=x_loan_age rename=(x_loan_age=nxt_age));

  if first.loan_id then ngaps_this_loan=0;  /*N of gaps for this loan */
  gap=nxt_age-x_loan_age;
  if last.loan_id=0 and gap^=1;
  ngaps_this_loan+1;

  retain max_ngap;  /*Track the maximum number of gaps */
  max_ngap=max(max_ngap,ngaps_this_loan);
  if dif(max_ngap) then call symput('max_ngap',cats(max_ngap));
run;

data want (keep=loan_id gapstart: gapsize:);
  do g=1 by 1 until (last.loan_id);
    set gaps;
    by loan_id;
    array gapstart{&amp;amp;max_ngap};
    array gapsize{&amp;amp;max_ngap};
    gapstart{g}=yyyymm;
    gapsize{g}=gap;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Mar 2021 03:08:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-variable-that-returns-gaps-in-panel-data/m-p/729269#M226927</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-03-26T03:08:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I create a variable that returns gaps in panel data?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-variable-that-returns-gaps-in-panel-data/m-p/729868#M227208</link>
      <description>This worked for me! Thank you! I will check out the PROC TIMESERIES too.</description>
      <pubDate>Mon, 29 Mar 2021 19:49:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-do-I-create-a-variable-that-returns-gaps-in-panel-data/m-p/729868#M227208</guid>
      <dc:creator>nbs98495</dc:creator>
      <dc:date>2021-03-29T19:49:33Z</dc:date>
    </item>
  </channel>
</rss>

