<?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: Calculating monthly employee count from start and end date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Calculating-monthly-employee-count-from-start-and-end-date/m-p/694855#M211950</link>
    <description>&lt;P&gt;What do you want the final result to look like? And is this for reporting purposes or do you want a SAS data set?&lt;/P&gt;</description>
    <pubDate>Wed, 28 Oct 2020 13:47:12 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2020-10-28T13:47:12Z</dc:date>
    <item>
      <title>Calculating monthly employee count from start and end date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-monthly-employee-count-from-start-and-end-date/m-p/694836#M211943</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need some help to find out if it is possible in SAS to program a monthly head count of employees.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the start dates and the end date like this example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Linda&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;11-02-2020&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;30-06-2022&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Jimmie&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;01-01-2021&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;31-08-2022&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Sean&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;01-01-2019&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;31-12-2021&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Maya&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;01-03-2019&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;31-10-2020&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope you can help&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2020 12:41:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-monthly-employee-count-from-start-and-end-date/m-p/694836#M211943</guid>
      <dc:creator>Steffy_SAS</dc:creator>
      <dc:date>2020-10-28T12:41:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating monthly employee count from start and end date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-monthly-employee-count-from-start-and-end-date/m-p/694855#M211950</link>
      <description>&lt;P&gt;What do you want the final result to look like? And is this for reporting purposes or do you want a SAS data set?&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2020 13:47:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-monthly-employee-count-from-start-and-end-date/m-p/694855#M211950</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-10-28T13:47:12Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating monthly employee count from start and end date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-monthly-employee-count-from-start-and-end-date/m-p/694871#M211957</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/282813"&gt;@Steffy_SAS&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need some help to find out if it is possible in SAS to program a monthly head count of employees.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the start dates and the end date like this example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;Linda&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;11-02-2020&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;30-06-2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;Jimmie&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;01-01-2021&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;31-08-2022&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;Sean&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;01-01-2019&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;31-12-2021&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;P&gt;Maya&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;01-03-2019&lt;/P&gt;
&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;31-10-2020&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope you can help&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If I understand your need then one approach would be create one record for each month for each employee and then count the records by&amp;nbsp; date.&lt;/P&gt;
&lt;P&gt;Assumes that you actually have SAS dates as numeric with a date format applied:&lt;/P&gt;
&lt;PRE&gt;data have;
  input name $ start :ddmmyy10. end :ddmmyy10.;
  format start end ddmmyy10.;
datalines;
Linda  11-02-2020 30-06-2022
Jimmie 01-01-2021 31-08-2022
Sean 01-01-2019 31-12-2021
Maya 01-03-2019 31-10-2020
;

data need;
   set have;
   monthyear = (intnx('month',start,0,'b'));
   do while (monthyear le (intnx('month',end,0,'b')) );
      output;
      monthyear = intnx('month',monthyear,1,'b');
   end;
   format monthyear monyy.;
run;

proc freq data=need;
   tables monthyear;
run;&lt;/PRE&gt;
&lt;P&gt;The intnx function is used to set the start of the period at the beginning of the month, not needed but may be a good idea, and then in the loop increases the value to the beginning of the next month.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Oct 2020 14:15:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-monthly-employee-count-from-start-and-end-date/m-p/694871#M211957</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-10-28T14:15:27Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating monthly employee count from start and end date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-monthly-employee-count-from-start-and-end-date/m-p/694885#M211965</link>
      <description>&lt;P&gt;Maybe somemthin like this&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input name $ start: ddmmyy10. end: mmddyy10.;
	format start end date9.;
	datalines;
Linda 11/02/2020 01/01/2022
Jimmie 10/01/2019 01/10/2021
Sean 11/01/2018 01/11/2020
Maya 12/01/2020 01/12/2023
;
run;

data temp;
	set have;
	temp_month = intck('MONTH',start,end);

	%*Kopierer unikke records til de manglende måneder;
	do i= 0 to temp_month;
		periode = intnx('MONTH', start, i, 'B' );
		output;
	end;
run;

proc  sql;
select year(periode) as year, month(periode) as month, count(1)
from temp
group by  year, calculated month
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Oct 2020 14:39:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-monthly-employee-count-from-start-and-end-date/m-p/694885#M211965</guid>
      <dc:creator>rudfaden</dc:creator>
      <dc:date>2020-10-28T14:39:10Z</dc:date>
    </item>
    <item>
      <title>Re: Calculating monthly employee count from start and end date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Calculating-monthly-employee-count-from-start-and-end-date/m-p/695122#M212065</link>
      <description>&lt;P&gt;This is just what I needed, thank you so much&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":smiling_face_with_smiling_eyes:"&gt;😊&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 09:35:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Calculating-monthly-employee-count-from-start-and-end-date/m-p/695122#M212065</guid>
      <dc:creator>Steffy_SAS</dc:creator>
      <dc:date>2020-10-29T09:35:49Z</dc:date>
    </item>
  </channel>
</rss>

