<?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 Creating multiple rows based on time interval between two variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-rows-based-on-time-interval-between-two/m-p/677560#M204391</link>
    <description>&lt;P&gt;I want to create multiple rows based on time interval between two variables. I've the data as below. We have 'Duration' value as 3 for each 'Year_mo' (2017-03 and 2017-06) in the data below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Branch	Segment	   Type    Year_mo	 Start_Mo	End_Mo	        Duration
71831234 7183_AS4  Cdir	   2017-03	 2017-03	2017-09	         3
71831234 7183_AS4  Cdir	   2017-06	 2017-03	2017-09	         3
&lt;/PRE&gt;
&lt;P&gt;Now I want to create as many as rows based on the value from the variable 'Duration' and I've to create one more variable called 'Cal_Month' which should have values in quarters&amp;nbsp;between time interval of the variables 'Start_Mo' and 'End_Mo&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;with group by 'Year_mo'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case values of 'Cal_Month' should be in 2017-03, 2017-06 and 2017-09. 'Duration' value is 3 for each each 'Year_mo'. So I need 3 observations for 'Year_mo' with the respective 'Cal_Month'&amp;nbsp; values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired Result is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Branch	 Segment      Type	Year_mo	Start_Mo  End_Mo   Cal_Month
71831234  7183_AS4    Cdir	2017-03	2017-03	  2017-09   2017-03
71831234   7183_AS4   Cdir	2017-03	2017-03	  2017-09   2017-06
71831234   7183_AS4   Cdir	2017-03	2017-03	  2017-09   2017-09
71831234   7183_AS4   Cdir	2017-06	2017-03	  2017-09   2017-03
71831234   7183_AS4   Cdir	2017-06	2017-03	  2017-09   2017-06
71831234   7183_AS4   Cdir	2017-06	2017-03	  2017-09   2017-09
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In real life I've data with 'Duration' from 1 to 9 and "Year_Mo' is also I have multiple Dates. To get the idea to tackle this Scenario, I just shared the sample data here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 18 Aug 2020 17:18:03 GMT</pubDate>
    <dc:creator>David_Billa</dc:creator>
    <dc:date>2020-08-18T17:18:03Z</dc:date>
    <item>
      <title>Creating multiple rows based on time interval between two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-rows-based-on-time-interval-between-two/m-p/677560#M204391</link>
      <description>&lt;P&gt;I want to create multiple rows based on time interval between two variables. I've the data as below. We have 'Duration' value as 3 for each 'Year_mo' (2017-03 and 2017-06) in the data below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Branch	Segment	   Type    Year_mo	 Start_Mo	End_Mo	        Duration
71831234 7183_AS4  Cdir	   2017-03	 2017-03	2017-09	         3
71831234 7183_AS4  Cdir	   2017-06	 2017-03	2017-09	         3
&lt;/PRE&gt;
&lt;P&gt;Now I want to create as many as rows based on the value from the variable 'Duration' and I've to create one more variable called 'Cal_Month' which should have values in quarters&amp;nbsp;between time interval of the variables 'Start_Mo' and 'End_Mo&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;with group by 'Year_mo'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case values of 'Cal_Month' should be in 2017-03, 2017-06 and 2017-09. 'Duration' value is 3 for each each 'Year_mo'. So I need 3 observations for 'Year_mo' with the respective 'Cal_Month'&amp;nbsp; values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Desired Result is,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Branch	 Segment      Type	Year_mo	Start_Mo  End_Mo   Cal_Month
71831234  7183_AS4    Cdir	2017-03	2017-03	  2017-09   2017-03
71831234   7183_AS4   Cdir	2017-03	2017-03	  2017-09   2017-06
71831234   7183_AS4   Cdir	2017-03	2017-03	  2017-09   2017-09
71831234   7183_AS4   Cdir	2017-06	2017-03	  2017-09   2017-03
71831234   7183_AS4   Cdir	2017-06	2017-03	  2017-09   2017-06
71831234   7183_AS4   Cdir	2017-06	2017-03	  2017-09   2017-09
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In real life I've data with 'Duration' from 1 to 9 and "Year_Mo' is also I have multiple Dates. To get the idea to tackle this Scenario, I just shared the sample data here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Aug 2020 17:18:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-rows-based-on-time-interval-between-two/m-p/677560#M204391</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-08-18T17:18:03Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple rows based on time interval between two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-rows-based-on-time-interval-between-two/m-p/677561#M204392</link>
      <description>&lt;P&gt;First, are all of your year_mo start_mo and end_mo variables actual SAS date values, i.e. numeric with an apparent format of YYMMD7.?&lt;/P&gt;</description>
      <pubDate>Tue, 18 Aug 2020 17:26:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-rows-based-on-time-interval-between-two/m-p/677561#M204392</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-18T17:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple rows based on time interval between two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-rows-based-on-time-interval-between-two/m-p/677568#M204398</link>
      <description>&lt;P&gt;Yes, all the variables (year_mo start_mo and end_mo) are SAS date values. I'm looking for logic to fit this requirement via SAS program.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Aug 2020 17:41:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-rows-based-on-time-interval-between-two/m-p/677568#M204398</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-08-18T17:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple rows based on time interval between two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-rows-based-on-time-interval-between-two/m-p/677604#M204411</link>
      <description>&lt;P&gt;This duplicates your wanted data given the starting data.&lt;/P&gt;
&lt;PRE&gt;data have;
 input Branch $ Segment $ Type $ Year_mo :anydtdte7. 
      Start_Mo :anydtdte7. End_Mo :anydtdte7. Duration;
   format year_mo start_mo end_mo yymmd7.;
datalines;
71831234 7183_AS4  Cdir	   2017-03	 2017-03	2017-09	         3
71831234 7183_AS4  Cdir	   2017-06	 2017-03	2017-09	         3
;

data want;
   set have;
   cal_month=start_mo;
   do until (cal_month &amp;gt; end_mo);
      output;
      cal_month=intnx('month',cal_month,duration);
   end;
   format cal_month yymmd7.;

run;&lt;/PRE&gt;
&lt;P&gt;You may run into interesting output if your duration value does not divide nicely in the number of months between start and end months.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note that I provide a way to create actual data for testing code in the form of a data step. That is the preferred manner of providing example data as then there is no need to ask questions about data types.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &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"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Aug 2020 19:32:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-rows-based-on-time-interval-between-two/m-p/677604#M204411</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-08-18T19:32:29Z</dc:date>
    </item>
  </channel>
</rss>

