<?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 changing the date (not the format?) in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313460#M61479</link>
    <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to change the date from DATETIME to date (with datepart) and then extract only month and year by changing format to MONYY7. I want to do so in order to count certain ID for each month. The issue is, SAS treats this date as previous dates, but it gives me the month, in example while using distinct I will get two separate lines with MAY 2016 and again MAY 2016 because days might differ. How to avoid that, to sum things up?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PROC SQL;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;CREATE TABLE&lt;/STRONG&gt; WORK.QUERY&amp;nbsp;AS&lt;BR /&gt;&lt;STRONG&gt;SELECT DISTINCT&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;datepart(t1.EXPIRE_DATE,9) FORMAT=MONYY7.,&lt;BR /&gt;t1.CONT_ID&lt;BR /&gt;&lt;STRONG&gt;FROM&lt;/STRONG&gt; CONTRACT&amp;nbsp;t1&lt;BR /&gt;&lt;STRONG&gt;GROUP&lt;/STRONG&gt; BY t1.EXPIRE_DATE;&lt;BR /&gt;&lt;STRONG&gt;QUIT&lt;/STRONG&gt;;&lt;/P&gt;</description>
    <pubDate>Tue, 22 Nov 2016 13:30:52 GMT</pubDate>
    <dc:creator>pkonopnicki</dc:creator>
    <dc:date>2016-11-22T13:30:52Z</dc:date>
    <item>
      <title>changing the date (not the format?)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313460#M61479</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to change the date from DATETIME to date (with datepart) and then extract only month and year by changing format to MONYY7. I want to do so in order to count certain ID for each month. The issue is, SAS treats this date as previous dates, but it gives me the month, in example while using distinct I will get two separate lines with MAY 2016 and again MAY 2016 because days might differ. How to avoid that, to sum things up?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;please help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PROC SQL;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;CREATE TABLE&lt;/STRONG&gt; WORK.QUERY&amp;nbsp;AS&lt;BR /&gt;&lt;STRONG&gt;SELECT DISTINCT&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;datepart(t1.EXPIRE_DATE,9) FORMAT=MONYY7.,&lt;BR /&gt;t1.CONT_ID&lt;BR /&gt;&lt;STRONG&gt;FROM&lt;/STRONG&gt; CONTRACT&amp;nbsp;t1&lt;BR /&gt;&lt;STRONG&gt;GROUP&lt;/STRONG&gt; BY t1.EXPIRE_DATE;&lt;BR /&gt;&lt;STRONG&gt;QUIT&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 13:30:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313460#M61479</guid>
      <dc:creator>pkonopnicki</dc:creator>
      <dc:date>2016-11-22T13:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: changing the date (not the format?)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313462#M61480</link>
      <description>&lt;P&gt;The format changes only the way the values are displayed, the values stay the same.&lt;/P&gt;
&lt;P&gt;You have to create a value that represents only the month, like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
expire_date = '22nov2016:13:53:24'dt;
output;
expire_date = '21nov2016:13:53:24'dt;
output;
run;

proc sql;
create table want as
select distinct put(datepart(expire_date),monyy7.) as exp_month
from have;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 13:37:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313462#M61480</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-22T13:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: changing the date (not the format?)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313463#M61481</link>
      <description>&lt;P&gt;When you use format, like&amp;nbsp;&lt;SPAN&gt;MONYY7., you dont change the value of the date variable,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;then if there are two different dates, you'll get them as distinct.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;As to your isuue, there are more than one solution.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I shall use your code with a change:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE WORK.QUERY&amp;nbsp;AS&lt;BR /&gt;SELECT DISTINCT&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;put(datepart(t1.EXPIRE_DATE,9),MONYY7.) as expire_date,&lt;/STRONG&gt;&lt;BR /&gt;t1.CONT_ID&lt;BR /&gt;FROM CONTRACT&amp;nbsp;t1&lt;BR /&gt;GROUP BY t1.EXPIRE_DATE;&lt;BR /&gt;QUIT;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 13:43:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313463#M61481</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-11-22T13:43:06Z</dc:date>
    </item>
    <item>
      <title>Re: changing the date (not the format?)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313466#M61483</link>
      <description>&lt;P&gt;I might have misunderstood you, but I tried this and it gives me same results:&lt;BR /&gt;&lt;BR /&gt;SELECT DISTINCT put(datepart(t1.EXPIRE_DATE, 9), MONYY7.) as YEAR_MONTH,&lt;BR /&gt;count(t1.CONT_ID)&lt;BR /&gt;FROM CIS2.CONTRACTS t1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/5948iACE30BAC49C8B072/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 13:48:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313466#M61483</guid>
      <dc:creator>pkonopnicki</dc:creator>
      <dc:date>2016-11-22T13:48:23Z</dc:date>
    </item>
    <item>
      <title>Re: changing the date (not the format?)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313467#M61484</link>
      <description>&lt;P&gt;Still another method would be to "normalize" the datepart() value with the intnx function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select distinct intnx('month',datepart(expire_date),0,'begin') format=monyy7. as exp_month
from have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Nov 2016 13:48:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313467#M61484</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-22T13:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: changing the date (not the format?)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313469#M61485</link>
      <description>&lt;P&gt;AFAIK, datepart() accepts only one argument. Maybe the ,9 is causing glitches. Try without.&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 13:52:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313469#M61485</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-22T13:52:49Z</dc:date>
    </item>
    <item>
      <title>Re: changing the date (not the format?)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313470#M61486</link>
      <description>&lt;P&gt;BTW, is CIS2 a SAS library or one in a DBMS?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 13:54:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313470#M61486</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-22T13:54:45Z</dc:date>
    </item>
    <item>
      <title>Re: changing the date (not the format?)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313473#M61487</link>
      <description>KurtBremser when I remove '9' or use your code starting with intnx it still gives me the same result : /</description>
      <pubDate>Tue, 22 Nov 2016 13:58:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313473#M61487</guid>
      <dc:creator>pkonopnicki</dc:creator>
      <dc:date>2016-11-22T13:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: changing the date (not the format?)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313474#M61488</link>
      <description>The one solution would be doing this&lt;BR /&gt;put(datepart(EXPIRE_DATE, 9), MONYY7.)&lt;BR /&gt;without count(cont_id), just regular cont_id and then in next query do the count.</description>
      <pubDate>Tue, 22 Nov 2016 14:01:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313474#M61488</guid>
      <dc:creator>pkonopnicki</dc:creator>
      <dc:date>2016-11-22T14:01:35Z</dc:date>
    </item>
    <item>
      <title>Re: changing the date (not the format?)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313475#M61489</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/113120"&gt;@pkonopnicki&lt;/a&gt; wrote:&lt;BR /&gt;KurtBremser when I remove '9' or use your code starting with intnx it still gives me the same result : /&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you still use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;group by expire_date;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;that is the culprit.&lt;/P&gt;
&lt;P&gt;I adapted my code&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select distinct put(datepart(expire_date),monyy7.) as exp_month, count(ID)
from have
group by calculated exp_month
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 22 Nov 2016 14:04:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313475#M61489</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-11-22T14:04:12Z</dc:date>
    </item>
    <item>
      <title>Re: changing the date (not the format?)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313480#M61490</link>
      <description>&lt;P&gt;I love you KurtBremser aka SAS Destroyer &lt;span class="lia-unicode-emoji" title=":face_blowing_a_kiss:"&gt;😘&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 22 Nov 2016 14:11:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/changing-the-date-not-the-format/m-p/313480#M61490</guid>
      <dc:creator>pkonopnicki</dc:creator>
      <dc:date>2016-11-22T14:11:36Z</dc:date>
    </item>
  </channel>
</rss>

