<?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: keep the VALUE for days that are within the first 5 or last 5 working days in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/keep-the-VALUE-for-days-that-are-within-the-first-5-or-last-5/m-p/610601#M177828</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;very grateful for your assistance! sorry for not being able to ask all questions at once, just forgot when I post the question. Have a great evening and thank you again!&lt;/P&gt;</description>
    <pubDate>Tue, 10 Dec 2019 02:33:30 GMT</pubDate>
    <dc:creator>JacAder</dc:creator>
    <dc:date>2019-12-10T02:33:30Z</dc:date>
    <item>
      <title>keep the VALUE for days that are within the first 5 or last 5 working days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-the-VALUE-for-days-that-are-within-the-first-5-or-last-5/m-p/610559#M177812</link>
      <description>&lt;P&gt;For each ID, keep the VALUE for days that are within the first 5 or last 5 working days.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;For example, for id1, 10/3/2019, 10/4/2019 and 10/7/2019 are within the first 5 working days of October 2019 (the first 5 working days in this case are Octboer 1,2,3,4,and 7),&amp;nbsp; while 10/28/2019 and 10/29/2019 are within the last 5 working days of October 2019.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;It is something like, first identify the first 5 or last 5 working days for each month, then compare the value in the dataset with the first 5 or last 5 working days of the month.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;How to achieve that? Really appreciate your kindly help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
informat ID $3. DATE mmddyy10. VALUE 2.;
format DATE mmddyy10.;
input  ID DATE VALUE;
cards;
id1	10/3/2019	1
id1	10/4/2019	2
id1	10/7/2019	3
id1	10/8/2019	4
id1	10/9/2019	5
id1	10/10/2019	6
id1	10/11/2019	7
id1	10/14/2019	8
id1	10/15/2019	9
id1	10/16/2019	10
id1	10/17/2019	11
id1	10/18/2019	12
id1	10/22/2019	13
id1	10/23/2019	14
id1	10/28/2019	15
id1	10/29/2019	16
id2	8/9/2018	17
id2	8/14/2018	18
id2	8/15/2018	19
id2	8/20/2018	20
id2	8/21/2018	21
id2	8/21/2018	22
id2	8/22/2018	23
id2	8/24/2018	24
id2	8/27/2018	25
id2	8/30/2018	26
id2	8/31/2018	27
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Dec 2019 21:22:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-the-VALUE-for-days-that-are-within-the-first-5-or-last-5/m-p/610559#M177812</guid>
      <dc:creator>JacAder</dc:creator>
      <dc:date>2019-12-09T21:22:09Z</dc:date>
    </item>
    <item>
      <title>Re: keep the VALUE for days that are within the first 5 or last 5 working days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-the-VALUE-for-days-that-are-within-the-first-5-or-last-5/m-p/610571#M177815</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/163151"&gt;@JacAder&lt;/a&gt;&amp;nbsp; &amp;nbsp;GROUPFORMAT with key indexing is fun way&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;


data have;
informat ID $3. DATE mmddyy10. VALUE 2.;
format DATE mmddyy10.;
input  ID DATE VALUE;
cards;
id1	10/3/2019	1
id1	10/4/2019	2
id1	10/7/2019	3
id1	10/8/2019	4
id1	10/9/2019	5
id1	10/10/2019	6
id1	10/11/2019	7
id1	10/14/2019	8
id1	10/15/2019	9
id1	10/16/2019	10
id1	10/17/2019	11
id1	10/18/2019	12
id1	10/22/2019	13
id1	10/23/2019	14
id1	10/28/2019	15
id1	10/29/2019	16
id2	8/9/2018	17
id2	8/14/2018	18
id2	8/15/2018	19
id2	8/20/2018	20
id2	8/21/2018	21
id2	8/21/2018	22
id2	8/22/2018	23
id2	8/24/2018	24
id2	8/27/2018	25
id2	8/30/2018	26
id2	8/31/2018	27
;
run;


data want;
 do _n_=1 by 1 until(last.DATE);
  set have;
  by id groupformat date;
  format date monyy. date1 mmddyy10.;;
  date1=date;
  array t(-3652:33237) _temporary_;
  if _n_=1 then do;
   do _iorc_=intnx('mon',date,0) by 1 until(_c=5);
    if weekday(_iorc_)  in (1,7) then continue;
	 _c=sum(_c,1);
     t(_iorc_)=1;
   end;
   do _iorc_=intnx('mon',date,0,'e') by -1 until(_c=10);
    if weekday(_iorc_)  in (1,7) then continue;
	 _c=sum(_c,1);
     t(_iorc_)=1;
   end;
  end;
  if t(date) then output;
end;
call missing(of t(*));
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 09 Dec 2019 22:12:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-the-VALUE-for-days-that-are-within-the-first-5-or-last-5/m-p/610571#M177815</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-09T22:12:58Z</dc:date>
    </item>
    <item>
      <title>Re: keep the VALUE for days that are within the first 5 or last 5 working days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-the-VALUE-for-days-that-are-within-the-first-5-or-last-5/m-p/610585#M177820</link>
      <description>&lt;P&gt;Many thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;!!&lt;/P&gt;&lt;P&gt;Just one more thing, your code is very concise, I have no idea how to modify the code to create another column, say, "order of the working day", indicating the order of those working dates within the month. For example,&amp;nbsp;10/3/2019 is the 3rd of the working days in October 2019, and&amp;nbsp;10/4/2019 is the 4th of the working days in October 2019, etc.&lt;/P&gt;&lt;P&gt;Keep the number of working days for each month would be great.&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="firstlast5wokingdays.png" style="width: 398px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/34573iA691547C86B1C5FD/image-size/large?v=v2&amp;amp;px=999" role="button" title="firstlast5wokingdays.png" alt="firstlast5wokingdays.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2019 23:23:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-the-VALUE-for-days-that-are-within-the-first-5-or-last-5/m-p/610585#M177820</guid>
      <dc:creator>JacAder</dc:creator>
      <dc:date>2019-12-09T23:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: keep the VALUE for days that are within the first 5 or last 5 working days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-the-VALUE-for-days-that-are-within-the-first-5-or-last-5/m-p/610591#M177823</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/163151"&gt;@JacAder&lt;/a&gt;&amp;nbsp; &amp;nbsp;Incomplete communication leads to DING DONG in the pendulum causing delays. Please post the requirement in full so we can offer solutions in one shot. Anyways, try the modified version below and let us know. if anything, I can only look into it tomorrow coz I am in a hurry to catch the bus and go home. But hey, global folks would help when we at Connecticut in Eastern Time are sleeping. Have a good evening&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
informat ID $3. DATE mmddyy10. VALUE 2.;
format DATE mmddyy10.;
input  ID DATE VALUE;
cards;
id1	10/3/2019	1
id1	10/4/2019	2
id1	10/7/2019	3
id1	10/8/2019	4
id1	10/9/2019	5
id1	10/10/2019	6
id1	10/11/2019	7
id1	10/14/2019	8
id1	10/15/2019	9
id1	10/16/2019	10
id1	10/17/2019	11
id1	10/18/2019	12
id1	10/22/2019	13
id1	10/23/2019	14
id1	10/28/2019	15
id1	10/29/2019	16
id2	8/9/2018	17
id2	8/14/2018	18
id2	8/15/2018	19
id2	8/20/2018	20
id2	8/21/2018	21
id2	8/21/2018	22
id2	8/22/2018	23
id2	8/24/2018	24
id2	8/27/2018	25
id2	8/30/2018	26
id2	8/31/2018	27
;
run;


data want;
 if _n_=1 then do;
   dcl hash H () ;
   h.definekey  ("date") ;
   h.definedata ("workday_order") ;
   h.definedone () ;
 end;
 do _n_=1 by 1until(last.DATE);
  set have;
  by id groupformat date;
  date1=date;
  format date monyy. date1 date9.;
  if _n_=1 then do;
  do _iorc_=intnx('mon',date,0) by 1 until(_c=5);
    if weekday(_iorc_)  in (1,7) then continue;
	 _c=sum(_c,1);
     h.add(key:_iorc_,data:_c);
  end;
  _t=_iorc_;
  do _iorc_=intnx('mon',date,0,'e') by -1 until(_c=10);
    if weekday(_iorc_)  in (1,7) then continue;
	 _c=sum(_c,1);
     workday_order=intck('weekday',_t,_iorc_)+5;
     h.add(key:_iorc_,data:workday_order);
  end;
  end;
  if h.find()=0 then do;
   num_of_workingdays=intck('weekday',intnx('mon',date,0),intnx('mon',date,0,'e'))+1;
   output;
  end;
 end;
 h.clear();
 drop _:;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 00:03:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-the-VALUE-for-days-that-are-within-the-first-5-or-last-5/m-p/610591#M177823</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-10T00:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: keep the VALUE for days that are within the first 5 or last 5 working days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/keep-the-VALUE-for-days-that-are-within-the-first-5-or-last-5/m-p/610601#M177828</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;very grateful for your assistance! sorry for not being able to ask all questions at once, just forgot when I post the question. Have a great evening and thank you again!&lt;/P&gt;</description>
      <pubDate>Tue, 10 Dec 2019 02:33:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/keep-the-VALUE-for-days-that-are-within-the-first-5-or-last-5/m-p/610601#M177828</guid>
      <dc:creator>JacAder</dc:creator>
      <dc:date>2019-12-10T02:33:30Z</dc:date>
    </item>
  </channel>
</rss>

