<?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: Divide month into 3 parts in timestamp in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Divide-month-into-3-parts-in-timestamp/m-p/592379#M169835</link>
    <description>&lt;P&gt;If I understand this right then below the code you're asking for.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  dttm=intnx('dtmonth',datetime(),0,'b');
  /* 1st of month */
  call symputx('dttm_first',put(dttm,datetime20.),'g');
  /* 10th of month */
  call symputx('dttm_10',put(intnx('dtday',dttm,9,'b'),datetime20.),'g');
  /* 11th of mont */ 
  call symputx('dttm_11',put(intnx('dtday',dttm,10,'b'),datetime20.),'g');
  /* 20th of mont */ 
  call symputx('dttm_20',put(intnx('dtday',dttm,19,'b'),datetime20.),'g');
  /* 21th of mont */ 
  call symputx('dttm_21',put(intnx('dtday',dttm,20,'b'),datetime20.),'g');
  /* last of mont */ 
  call symputx('dttm_last',put(intnx('dtmonth',dttm,0,'e'),datetime20.),'g');
  stop;
run;
%put &amp;amp;=dttm_first;
%put &amp;amp;=dttm_10;
%put &amp;amp;=dttm_11;
%put &amp;amp;=dttm_20;
%put &amp;amp;=dttm_21;
%put &amp;amp;=dttm_last;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;DTTM_FIRST=01SEP2019:00:00:00
DTTM_10=10SEP2019:00:00:00
DTTM_11=11SEP2019:00:00:00
DTTM_20=20SEP2019:00:00:00
DTTM_21=21SEP2019:00:00:00
DTTM_LAST=30SEP2019:23:59:59&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 28 Sep 2019 10:05:35 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2019-09-28T10:05:35Z</dc:date>
    <item>
      <title>Divide month into 3 parts in timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Divide-month-into-3-parts-in-timestamp/m-p/592378#M169834</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to divide current month in 3 parts of days.&lt;/P&gt;&lt;P&gt;1-10 in part1&lt;/P&gt;&lt;P&gt;11-20 in part2&lt;/P&gt;&lt;P&gt;21-last day of month in part3. So there are 6 macro variables to be created like&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;01SEP2019:00:00:00&lt;/P&gt;&lt;P&gt;10SEP2019:00:00:00&lt;/P&gt;&lt;P&gt;11SEP2019:00:00:00&lt;/P&gt;&lt;P&gt;20SEP2019:00:00:00&lt;/P&gt;&lt;P&gt;21SEP2019:00:00:00&lt;/P&gt;&lt;P&gt;30SEP2019:00:00:00&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have managed to create first and last day of the month as below. But somehow unable to create remaining variables. Below is the code I have tried. Thanks in advance&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DATA _NULL_;&lt;BR /&gt;CALL SYMPUT('a',CATS(put(INTNX("MONTH",today()-2,0,"B"),DATE9.),":00:00:00"));&lt;BR /&gt;CALL SYMPUT('b',CATS(put(INTNX("MONTH",today()-2,0,"E"),DATE9.),":00:00:00"));&lt;BR /&gt;CALL SYMPUT ('ORA_PREV_MON_E',CATS(put(INTNX("MONTH",today(),-1,"E"),DATE9.),":00:00:00"));&lt;BR /&gt;/*CALL SYMPUT ("ORA_CURR_MON",cat("'",PUT(MONTH,date9.),"'"));;*/&lt;BR /&gt;RUN;&lt;BR /&gt;%put &amp;amp;a &amp;amp;b &amp;amp;ORA_PREV_MON_E;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Sep 2019 08:51:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Divide-month-into-3-parts-in-timestamp/m-p/592378#M169834</guid>
      <dc:creator>Swapnil_21</dc:creator>
      <dc:date>2019-09-28T08:51:17Z</dc:date>
    </item>
    <item>
      <title>Re: Divide month into 3 parts in timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Divide-month-into-3-parts-in-timestamp/m-p/592379#M169835</link>
      <description>&lt;P&gt;If I understand this right then below the code you're asking for.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  dttm=intnx('dtmonth',datetime(),0,'b');
  /* 1st of month */
  call symputx('dttm_first',put(dttm,datetime20.),'g');
  /* 10th of month */
  call symputx('dttm_10',put(intnx('dtday',dttm,9,'b'),datetime20.),'g');
  /* 11th of mont */ 
  call symputx('dttm_11',put(intnx('dtday',dttm,10,'b'),datetime20.),'g');
  /* 20th of mont */ 
  call symputx('dttm_20',put(intnx('dtday',dttm,19,'b'),datetime20.),'g');
  /* 21th of mont */ 
  call symputx('dttm_21',put(intnx('dtday',dttm,20,'b'),datetime20.),'g');
  /* last of mont */ 
  call symputx('dttm_last',put(intnx('dtmonth',dttm,0,'e'),datetime20.),'g');
  stop;
run;
%put &amp;amp;=dttm_first;
%put &amp;amp;=dttm_10;
%put &amp;amp;=dttm_11;
%put &amp;amp;=dttm_20;
%put &amp;amp;=dttm_21;
%put &amp;amp;=dttm_last;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;PRE&gt;DTTM_FIRST=01SEP2019:00:00:00
DTTM_10=10SEP2019:00:00:00
DTTM_11=11SEP2019:00:00:00
DTTM_20=20SEP2019:00:00:00
DTTM_21=21SEP2019:00:00:00
DTTM_LAST=30SEP2019:23:59:59&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Sep 2019 10:05:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Divide-month-into-3-parts-in-timestamp/m-p/592379#M169835</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-09-28T10:05:35Z</dc:date>
    </item>
    <item>
      <title>Re: Divide month into 3 parts in timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Divide-month-into-3-parts-in-timestamp/m-p/592387#M169837</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292735"&gt;@Swapnil_21&lt;/a&gt;&amp;nbsp;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;&amp;nbsp; - You created macro variables holding the limit datetime of each part,&lt;/P&gt;
&lt;P&gt;More available would be to know &lt;STRONG&gt;what usage&lt;/STRONG&gt; is done with those macro variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe if you look for categories: A B C as 1st, 2nd, 3rd part of a month - is it not enough to check&lt;/P&gt;
&lt;P&gt;the day only:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if day(&amp;lt;date or datetime&amp;gt;) le 10 then category = 'A'; else
if day(&amp;lt;date or datetime&amp;gt;) le 20 then category = 'B'; else category = 'C';&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does the data have one month data only? what if there are more then one month? what if it is not September?&lt;/P&gt;
&lt;P&gt;If you want to use the macros as labels in a report or a graph - are they not too long ?&lt;/P&gt;</description>
      <pubDate>Sat, 28 Sep 2019 12:22:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Divide-month-into-3-parts-in-timestamp/m-p/592387#M169837</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-09-28T12:22:26Z</dc:date>
    </item>
    <item>
      <title>Re: Divide month into 3 parts in timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Divide-month-into-3-parts-in-timestamp/m-p/592417#M169852</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292735"&gt;@Swapnil_21&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Heed what&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;has written and look no further than&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447"&gt;@Patrick&lt;/a&gt;'s response if you need macro variables (though I can't see what for).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Normally, in light of your question a typical task would go along these lines: Given a SAS datetime value, generate a variable to indicate which part of the month the datetime belongs. Its values would be 1 for the days 1-10, 2 for 11-20, and 3 for 21+.&amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When you have to deal with &lt;EM&gt;ranges&lt;/EM&gt;, the SAS in/formats are the tools specifically designed for the purpose; in fact, any in/format argument is always a range (even in the case its endpoints are the same). Hence, a natural way of addressing the task would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;                                    
  value monpart low-10=1 11-20=2 21-high=3 ;     
run ;                                            
                                                 
data _null_ ;                                    
  input dt datetime. ;                           
  monpart = put (day (datepart (dt)), monpart.) ;
  put monpart= ;                                 
  cards ;                                        
01SEP2019:00:00:00                               
10SEP2019:00:00:00                               
11SEP2019:00:00:00                               
20SEP2019:00:00:00                               
21SEP2019:00:00:00                               
30SEP2019:00:00:00                               
;                                                
run ;                                            
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The expression for MONPART above generates a character variable $1. In/formats cannot generate a numeric variable to numeric variable (number-to-number) correspondence all by themselves due to their nature, so if you want a numeric variable as the response, change the expression to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  monpart = input (put (day (datepart (dt)), monpart.), 1.) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;On the other hand, when the ranges are numeric and equidistant, as in your case, arithmetic can be used to relate a number-to-number directly, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_ ;                                
  input dt datetime. ;                       
  monpart = ceil (day (datepart (dt)) / 10) ;
  put monpart= ;                             
  cards ;                                    
01SEP2019:00:00:00                           
10SEP2019:00:00:00                           
11SEP2019:00:00:00                           
20SEP2019:00:00:00                           
21SEP2019:00:00:00                           
30SEP2019:00:00:00                           
;                                            
run ;                                        
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Sep 2019 18:44:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Divide-month-into-3-parts-in-timestamp/m-p/592417#M169852</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-09-28T18:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: Divide month into 3 parts in timestamp</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Divide-month-into-3-parts-in-timestamp/m-p/592717#M169967</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292735"&gt;@Swapnil_21&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I need to divide current month in 3 parts of days.&lt;/P&gt;
&lt;P&gt;1-10 in part1&lt;/P&gt;
&lt;P&gt;11-20 in part2&lt;/P&gt;
&lt;P&gt;21-last day of month in part3. So there are 6 macro variables to be created like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;01SEP2019:00:00:00&lt;/P&gt;
&lt;P&gt;10SEP2019:00:00:00&lt;/P&gt;
&lt;P&gt;11SEP2019:00:00:00&lt;/P&gt;
&lt;P&gt;20SEP2019:00:00:00&lt;/P&gt;
&lt;P&gt;21SEP2019:00:00:00&lt;/P&gt;
&lt;P&gt;30SEP2019:00:00:00&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have managed to create first and last day of the month as below. But somehow unable to create remaining variables. Below is the code I have tried. Thanks in advance&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;DATA _NULL_;&lt;BR /&gt;CALL SYMPUT('a',CATS(put(INTNX("MONTH",today()-2,0,"B"),DATE9.),":00:00:00"));&lt;BR /&gt;CALL SYMPUT('b',CATS(put(INTNX("MONTH",today()-2,0,"E"),DATE9.),":00:00:00"));&lt;BR /&gt;CALL SYMPUT ('ORA_PREV_MON_E',CATS(put(INTNX("MONTH",today(),-1,"E"),DATE9.),":00:00:00"));&lt;BR /&gt;/*CALL SYMPUT ("ORA_CURR_MON",cat("'",PUT(MONTH,date9.),"'"));;*/&lt;BR /&gt;RUN;&lt;BR /&gt;%put &amp;amp;a &amp;amp;b &amp;amp;ORA_PREV_MON_E;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You may strongly want to consider 1) making these DATE values if the time is always 00:00:00 and&lt;/P&gt;
&lt;P&gt;2) looking at the TENDAY interval option for the INTNX and INTCK functions: I use October in the following example to demonstrate what happens in months with 31 days.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
   do day = 1,9,10,11,19,20,21,29,30,31;
      date= mdy(10,day,2019);
      date2 = intnx('tenday',date,0,'b');
      format date date2 date9.;
      output;
   end;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 30 Sep 2019 15:27:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Divide-month-into-3-parts-in-timestamp/m-p/592717#M169967</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-30T15:27:07Z</dc:date>
    </item>
  </channel>
</rss>

