<?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: MONTH function not working properly in sashelp.prdsal3 in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/MONTH-function-not-working-properly-in-sashelp-prdsal3/m-p/471259#M14771</link>
    <description>&lt;P&gt;Sorry, I want output like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;MONTH&amp;nbsp; 1997&amp;nbsp; 1998&lt;/STRONG&gt;&amp;nbsp; column name&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't want missing or null value. and, also want PROC SQL query if it's possible.&lt;/P&gt;&lt;P&gt;Thank You.&lt;/P&gt;</description>
    <pubDate>Mon, 18 Jun 2018 23:03:34 GMT</pubDate>
    <dc:creator>kishangabani</dc:creator>
    <dc:date>2018-06-18T23:03:34Z</dc:date>
    <item>
      <title>MONTH function not working properly in sashelp.prdsal3</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/MONTH-function-not-working-properly-in-sashelp-prdsal3/m-p/471246#M14766</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
 create table m as
 select distinct month 
 from sashelp.prdsal3
;
 quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;STRONG&gt;MONTH&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Jan&lt;BR /&gt;Feb&lt;BR /&gt;Mar&lt;BR /&gt;Apr&lt;BR /&gt;May&lt;BR /&gt;Jun&lt;BR /&gt;Jul&lt;BR /&gt;Aug&lt;BR /&gt;Sep&lt;BR /&gt;Oct&lt;BR /&gt;Nov&lt;BR /&gt;Dec&lt;BR /&gt;Jan&lt;BR /&gt;Feb&lt;BR /&gt;Mar&lt;BR /&gt;Apr&lt;BR /&gt;May&lt;BR /&gt;Jun&lt;BR /&gt;Jul&lt;BR /&gt;Aug&lt;BR /&gt;Sep&lt;BR /&gt;Oct&lt;BR /&gt;Nov&lt;BR /&gt;Dec&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Total month is 24.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select month,
			case
			when year=1997 then sum(actual)
			end as _1997
			,
			case
			when year=1998 then sum(actual)
			end as _1998
from sashelp.prdsal3

group by 1;

quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;OUTPUT:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 290px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21255i108713D9BB0988F8/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to properly to set month. I want to sum of column 'ACTUAL'.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Jan 2019 22:20:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/MONTH-function-not-working-properly-in-sashelp-prdsal3/m-p/471246#M14766</guid>
      <dc:creator>kishangabani</dc:creator>
      <dc:date>2019-01-06T22:20:52Z</dc:date>
    </item>
    <item>
      <title>Re: MONTH function not working properly in sashelp.prdsal3</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/MONTH-function-not-working-properly-in-sashelp-prdsal3/m-p/471247#M14767</link>
      <description>&lt;P&gt;Can you clarify your requirement again please without your code in simple sentences, like what you want to accomplish&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Do you want to sum the actual obs for year 1997 and 1998 ?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 22:00:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/MONTH-function-not-working-properly-in-sashelp-prdsal3/m-p/471247#M14767</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-06-18T22:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: MONTH function not working properly in sashelp.prdsal3</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/MONTH-function-not-working-properly-in-sashelp-prdsal3/m-p/471249#M14768</link>
      <description>&lt;P&gt;PROC SQL doesn't respect SAS formats. So if your variable is a SAS date with a monname format you'll get this type of result. Instead you need to convert it over to an actual month value first, though this can cause other issues later on.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This can replicate your problem:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    title;footnote;
    data demo;
    set sashelp.stocks;
    format date monname3.;
    run;

    proc sql;
    create table demo_wrong as
    select distinct date
    from demo;

    create table demo_right as
    select distinct put(date, monname3.) as monName
    from demo;
    quit;

    proc print data=demo_wrong (obs=20);
    proc print data=demo_right (obs=20);
    run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/191037"&gt;@kishangabani&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
 create table m as
 select distinct month 
 from sashelp.prdsal3
;
 quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;MONTH&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Jan&lt;BR /&gt;Feb&lt;BR /&gt;Mar&lt;BR /&gt;Apr&lt;BR /&gt;May&lt;BR /&gt;Jun&lt;BR /&gt;Jul&lt;BR /&gt;Aug&lt;BR /&gt;Sep&lt;BR /&gt;Oct&lt;BR /&gt;Nov&lt;BR /&gt;Dec&lt;BR /&gt;Jan&lt;BR /&gt;Feb&lt;BR /&gt;Mar&lt;BR /&gt;Apr&lt;BR /&gt;May&lt;BR /&gt;Jun&lt;BR /&gt;Jul&lt;BR /&gt;Aug&lt;BR /&gt;Sep&lt;BR /&gt;Oct&lt;BR /&gt;Nov&lt;BR /&gt;Dec&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Total month is 24.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select month,
			case
			when year=1997 then sum(actual)
			end as _1997
			,
			case
			when year=1998 then sum(actual)
			end as _1998
from sashelp.prdsal3

group by 1;

quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;OUTPUT:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 290px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/21255i108713D9BB0988F8/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to properly to set month. I want to sum of column 'ACTUAL'.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 22:11:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/MONTH-function-not-working-properly-in-sashelp-prdsal3/m-p/471249#M14768</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-18T22:11:44Z</dc:date>
    </item>
    <item>
      <title>Re: MONTH function not working properly in sashelp.prdsal3</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/MONTH-function-not-working-properly-in-sashelp-prdsal3/m-p/471251#M14769</link>
      <description>&lt;P&gt;Also, you'd be better off using PROC REPORT, TABULATE or MEANS to generate your results and then pivot it with PROC TRANSPOSE. Otherwise you must know all the years ahead of time, whereas the approach above would be dynamic instead.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 22:12:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/MONTH-function-not-working-properly-in-sashelp-prdsal3/m-p/471251#M14769</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-18T22:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: MONTH function not working properly in sashelp.prdsal3</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/MONTH-function-not-working-properly-in-sashelp-prdsal3/m-p/471256#M14770</link>
      <description>&lt;P&gt;One of the problems with using a format that maps multiple distinct values to the same displayed value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The variable MONTH in that dataset has date values to which the MONNAME format has been attached. If you look at the actual values (or use a different format) you will see what is happening.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql  ;
select
  year
, month
, month(month) format=z2. as MonthNum 
, month as Day label='Day' format=yymmdd10.
, sum(actual) as Total
 from sashelp.prdsal3
 group by 1,2,3,4
 ;
 quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;             Month
Year  Month    Num         Day     Total
----------------------------------------
1997    Jan     01  1993-01-01    407515
1997    Feb     02  1993-02-01    419927
1997    Mar     03  1993-03-01    396236
1997    Apr     04  1993-04-01    413626
1997    May     05  1993-05-01    417042
1997    Jun     06  1993-06-01    409394
1997    Jul     07  1993-07-01    423352
1997    Aug     08  1993-08-01    412309
1997    Sep     09  1993-09-01    421428
1997    Oct     10  1993-10-01    427881
1997    Nov     11  1993-11-01    415825
1997    Dec     12  1993-12-01    415795
1998    Jan     01  1994-01-01  444612.3
1998    Feb     02  1994-02-01  456635.3
1998    Mar     03  1994-03-01  465384.7
1998    Apr     04  1994-04-01  461707.4
1998    May     05  1994-05-01  455460.5
1998    Jun     06  1994-06-01    456412
1998    Jul     07  1994-07-01  471626.1
1998    Aug     08  1994-08-01  463702.8
1998    Sep     09  1994-09-01    450285
1998    Oct     10  1994-10-01  464220.9
1998    Nov     11  1994-11-01  464501.4
1998    Dec     12  1994-12-01  481884.7&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 23:01:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/MONTH-function-not-working-properly-in-sashelp-prdsal3/m-p/471256#M14770</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-06-18T23:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: MONTH function not working properly in sashelp.prdsal3</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/MONTH-function-not-working-properly-in-sashelp-prdsal3/m-p/471259#M14771</link>
      <description>&lt;P&gt;Sorry, I want output like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;MONTH&amp;nbsp; 1997&amp;nbsp; 1998&lt;/STRONG&gt;&amp;nbsp; column name&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't want missing or null value. and, also want PROC SQL query if it's possible.&lt;/P&gt;&lt;P&gt;Thank You.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 23:03:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/MONTH-function-not-working-properly-in-sashelp-prdsal3/m-p/471259#M14771</guid>
      <dc:creator>kishangabani</dc:creator>
      <dc:date>2018-06-18T23:03:34Z</dc:date>
    </item>
    <item>
      <title>Re: MONTH function not working properly in sashelp.prdsal3</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/MONTH-function-not-working-properly-in-sashelp-prdsal3/m-p/471262#M14772</link>
      <description>&lt;P&gt;yes, thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but, I want to like&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;MONTH&amp;nbsp; 1997&amp;nbsp; 1998&amp;nbsp; &amp;lt;-- colmn name,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in month column only &lt;STRONG&gt;Jan-Dec &lt;/STRONG&gt;for SUM(ACTUAL) of year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Jun 2018 23:13:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/MONTH-function-not-working-properly-in-sashelp-prdsal3/m-p/471262#M14772</guid>
      <dc:creator>kishangabani</dc:creator>
      <dc:date>2018-06-18T23:13:52Z</dc:date>
    </item>
    <item>
      <title>Re: MONTH function not working properly in sashelp.prdsal3</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/MONTH-function-not-working-properly-in-sashelp-prdsal3/m-p/471264#M14773</link>
      <description>&lt;P&gt;ONE: You never used the "month" function.&lt;/P&gt;
&lt;P&gt;Two: Reports can often be done with a report procedure:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc tabulate data=sashelp.prdsal3;
   class month;
   class year;
   var actual;
   table month='',
         year=''*actual=''*sum=''
         /box='Month'
   ;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 18 Jun 2018 23:38:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/MONTH-function-not-working-properly-in-sashelp-prdsal3/m-p/471264#M14773</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-06-18T23:38:57Z</dc:date>
    </item>
    <item>
      <title>Re: MONTH function not working properly in sashelp.prdsal3</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/MONTH-function-not-working-properly-in-sashelp-prdsal3/m-p/471274#M14774</link>
      <description>&lt;P&gt;It's possible, but inefficient.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Summary statistics;
proc means data=sashelp.prdsal3 noprint nway;
    class month year;
    var actual;
    output out=summary sum(actual)=total_sales;
run;

*format for display;
proc transpose data=summary out=want (drop=_:) prefix=Year;
    by month;
    id year;
    var total_sales;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The SQL solution works but you have to know the years ahead of time AND code it for each year individually.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want_sql as
select put(month, monname3.) as month, 
sum(case when year=1997 then actual else 0 end) as year1997 format=dollar32.2,
sum(case when year=1998 then actual else 0 end) as year1998 format=dollar32.2
from sashelp.prdsal3
group by calculated month;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/191037"&gt;@kishangabani&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Sorry, I want output like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;MONTH&amp;nbsp; 1997&amp;nbsp; 1998&lt;/STRONG&gt;&amp;nbsp; column name&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't want missing or null value. and, also want PROC SQL query if it's possible.&lt;/P&gt;
&lt;P&gt;Thank You.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 19 Jun 2018 00:39:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/MONTH-function-not-working-properly-in-sashelp-prdsal3/m-p/471274#M14774</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-06-19T00:39:54Z</dc:date>
    </item>
  </channel>
</rss>

