<?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: Insert empty rows until certain conditions met in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Insert-empty-rows-until-certain-conditions-met/m-p/724229#M224835</link>
    <description>&lt;P&gt;Superb! Thanks.&lt;/P&gt;</description>
    <pubDate>Sat, 06 Mar 2021 21:25:48 GMT</pubDate>
    <dc:creator>_MooMoo</dc:creator>
    <dc:date>2021-03-06T21:25:48Z</dc:date>
    <item>
      <title>Insert empty rows until certain conditions met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-empty-rows-until-certain-conditions-met/m-p/724223#M224832</link>
      <description>&lt;P&gt;Hello SAS communities!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have following data set.&amp;nbsp;&lt;/P&gt;
&lt;TABLE border="1"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="14.285714285714286%"&gt;id&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;start&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;end&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;X&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="14.285714285714286%"&gt;1&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;1/15/2021&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;1/21/2021&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;1/02/2021&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="14.285714285714286%"&gt;2&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;1/22/2021&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;1/28/2021&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;1/09/2021&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;And I would like to output following data set.&lt;/P&gt;
&lt;TABLE border="1"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="143.636px" height="29px"&gt;id&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;start&amp;nbsp;&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;end&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;X&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="143.636px" height="29px"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;&lt;STRONG&gt;1/01/2021&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;&lt;STRONG&gt;1/07/2021&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;&lt;STRONG&gt;1/02/2021&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="143.636px" height="29px"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;&lt;STRONG&gt;1/08/2021&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;&lt;STRONG&gt;1/14/2021&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;&lt;STRONG&gt;1/02/2021&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="143.636px" height="29px"&gt;1&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;1/15/2021&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;1/21/2021&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;1/02/2021&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="143.636px" height="29px"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;&lt;STRONG&gt;1/08/2021&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;&lt;STRONG&gt;1/14/2021&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;&lt;STRONG&gt;1/09/2021&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="143.636px" height="29px"&gt;&lt;STRONG&gt;2&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;&lt;STRONG&gt;1/15/2021&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;&lt;STRONG&gt;1/21/2021&lt;/STRONG&gt;&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;&lt;STRONG&gt;1/09/2021&lt;/STRONG&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="143.636px" height="29px"&gt;2&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;1/22/2021&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;1/28/2021&lt;/TD&gt;
&lt;TD width="143.03px" height="29px"&gt;1/09/2021&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The rule is.... if X is not in between start and end, create rows until X is in between start and end. For example, from the above table, rows in bold are added.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any type of advice is greatly appreciated! Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Mar 2021 20:07:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-empty-rows-until-certain-conditions-met/m-p/724223#M224832</guid>
      <dc:creator>_MooMoo</dc:creator>
      <dc:date>2021-03-06T20:07:03Z</dc:date>
    </item>
    <item>
      <title>Re: Insert empty rows until certain conditions met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-empty-rows-until-certain-conditions-met/m-p/724224#M224833</link>
      <description>&lt;P&gt;You supplied the rule&amp;nbsp;&lt;STRONG&gt;when&lt;/STRONG&gt; to add observation. But &lt;STRONG&gt;what are the rules to define START and END&lt;/STRONG&gt; for each added line, while X seems to be retained and copied to those added lnes.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Mar 2021 20:19:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-empty-rows-until-certain-conditions-met/m-p/724224#M224833</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2021-03-06T20:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: Insert empty rows until certain conditions met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-empty-rows-until-certain-conditions-met/m-p/724227#M224834</link>
      <description>&lt;P&gt;Looks like you want to move the dates by one week at a time. So calculate the number of weeks and run a DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id (start  end x) (:mmddyy.);
  format start end x yymmdd10.;
cards;
1 1/15/2021 1/21/2021 1/02/2021
2 1/22/2021 1/28/2021 1/09/2021
;

data want ;
  set have ;
  diff = intck('week',start,x);
  do offset=min(0,diff) to max(0,diff) ;
    new_start = intnx('week',start,offset,'s');
    new_end   = intnx('week',end,offset,'s');
    output;
  end;
  format new_start new_end yymmdd10.;
  rename start=original_start end=original_end
         new_start=start new_end=end
  ;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;              original_     original_
Obs    id         start           end             x    diff    offset         start           end

 1      1    2021-01-15    2021-01-21    2021-01-02     -2       -2      2021-01-01    2021-01-07
 2      1    2021-01-15    2021-01-21    2021-01-02     -2       -1      2021-01-08    2021-01-14
 3      1    2021-01-15    2021-01-21    2021-01-02     -2        0      2021-01-15    2021-01-21
 4      2    2021-01-22    2021-01-28    2021-01-09     -2       -2      2021-01-08    2021-01-14
 5      2    2021-01-22    2021-01-28    2021-01-09     -2       -1      2021-01-15    2021-01-21
 6      2    2021-01-22    2021-01-28    2021-01-09     -2        0      2021-01-22    2021-01-28
&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 Mar 2021 20:36:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-empty-rows-until-certain-conditions-met/m-p/724227#M224834</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-06T20:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: Insert empty rows until certain conditions met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Insert-empty-rows-until-certain-conditions-met/m-p/724229#M224835</link>
      <description>&lt;P&gt;Superb! Thanks.&lt;/P&gt;</description>
      <pubDate>Sat, 06 Mar 2021 21:25:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Insert-empty-rows-until-certain-conditions-met/m-p/724229#M224835</guid>
      <dc:creator>_MooMoo</dc:creator>
      <dc:date>2021-03-06T21:25:48Z</dc:date>
    </item>
  </channel>
</rss>

