<?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 Juletip #8 - Making periods from time spans in SAS Community Nordic</title>
    <link>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-8-Making-periods-from-time-spans/m-p/784836#M363</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Sometimes it is necessary to reorganize data in periods instead of having the data 	            */
/* in one row per time span. This example combines the INTNX and INTCK functions to do that			*/

data christmas_periods;
  length christmas_food1 christmas_food2 $ 22;
  input christmas_food1 $ christmas_food2 $ start_date: date9. end_date :date9. quantum;
  format start_date end_date ddmmyyp10.;
  cards;
Trouth VanillaPudding 01dec2021 23dec2021 20
Ribs PepperCake 24dec2021 27dec2021 5
ChristmasPudding Beer 28dec2021 10jan2022 10
;
run;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nortrh_3-1638947498209.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66489iD15F1459BE9F7363/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nortrh_3-1638947498209.png" alt="nortrh_3-1638947498209.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Use the INTNX function to make periods from date spans	*/
data period_day(drop=i);
  set christmas_periods;
	number_of_days=end_date-start_date;
	do i=0 to number_of_days;
	  date=intnx('day',start_date,i);
	  quantity=quantum/number_of_days;
	  output;
	end;
	format date ddmmyy10.;
run;
&lt;/CODE&gt;&lt;/PRE&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="nortrh_4-1638947556450.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66490i4DB667B05B1B7FC2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nortrh_4-1638947556450.png" alt="nortrh_4-1638947556450.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Combine the INTCK and the INTNX functions to make periods other than days	*/
data period_week;
  set christmas_periods;
	number_of_weeks=intck('weekv',start_date,end_date);
	do i=0 to number_of_weeks;
	  week=intnx('weekv',start_date,i);
	  quantity=quantum/number_of_weeks;
	  output;
	end;
	format week yyweekv8.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nortrh_5-1638947599754.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66491iB5DA098089A7A614/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nortrh_5-1638947599754.png" alt="nortrh_5-1638947599754.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;One of the advantages of this technique is that it is possible to distribute measures on time periods other than those on the basic data. A disadvantage could be that it generates a lot of rows in the result data set, but SAS is capable to handle that!&lt;/P&gt;</description>
    <pubDate>Wed, 08 Dec 2021 07:32:36 GMT</pubDate>
    <dc:creator>nortrh</dc:creator>
    <dc:date>2021-12-08T07:32:36Z</dc:date>
    <item>
      <title>Juletip #8 - Making periods from time spans</title>
      <link>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-8-Making-periods-from-time-spans/m-p/784836#M363</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Sometimes it is necessary to reorganize data in periods instead of having the data 	            */
/* in one row per time span. This example combines the INTNX and INTCK functions to do that			*/

data christmas_periods;
  length christmas_food1 christmas_food2 $ 22;
  input christmas_food1 $ christmas_food2 $ start_date: date9. end_date :date9. quantum;
  format start_date end_date ddmmyyp10.;
  cards;
Trouth VanillaPudding 01dec2021 23dec2021 20
Ribs PepperCake 24dec2021 27dec2021 5
ChristmasPudding Beer 28dec2021 10jan2022 10
;
run;&lt;BR /&gt;&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nortrh_3-1638947498209.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66489iD15F1459BE9F7363/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nortrh_3-1638947498209.png" alt="nortrh_3-1638947498209.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Use the INTNX function to make periods from date spans	*/
data period_day(drop=i);
  set christmas_periods;
	number_of_days=end_date-start_date;
	do i=0 to number_of_days;
	  date=intnx('day',start_date,i);
	  quantity=quantum/number_of_days;
	  output;
	end;
	format date ddmmyy10.;
run;
&lt;/CODE&gt;&lt;/PRE&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="nortrh_4-1638947556450.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66490i4DB667B05B1B7FC2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nortrh_4-1638947556450.png" alt="nortrh_4-1638947556450.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Combine the INTCK and the INTNX functions to make periods other than days	*/
data period_week;
  set christmas_periods;
	number_of_weeks=intck('weekv',start_date,end_date);
	do i=0 to number_of_weeks;
	  week=intnx('weekv',start_date,i);
	  quantity=quantum/number_of_weeks;
	  output;
	end;
	format week yyweekv8.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="nortrh_5-1638947599754.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66491iB5DA098089A7A614/image-size/medium?v=v2&amp;amp;px=400" role="button" title="nortrh_5-1638947599754.png" alt="nortrh_5-1638947599754.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;One of the advantages of this technique is that it is possible to distribute measures on time periods other than those on the basic data. A disadvantage could be that it generates a lot of rows in the result data set, but SAS is capable to handle that!&lt;/P&gt;</description>
      <pubDate>Wed, 08 Dec 2021 07:32:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Community-Nordic/Juletip-8-Making-periods-from-time-spans/m-p/784836#M363</guid>
      <dc:creator>nortrh</dc:creator>
      <dc:date>2021-12-08T07:32:36Z</dc:date>
    </item>
  </channel>
</rss>

