<?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: How to group by calculated variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-group-by-calculated-variable/m-p/343979#M79012</link>
    <description>The last solution is very interesting. Where can I learn more about using format in that way?</description>
    <pubDate>Fri, 24 Mar 2017 08:02:59 GMT</pubDate>
    <dc:creator>afiqcjohari</dc:creator>
    <dc:date>2017-03-24T08:02:59Z</dc:date>
    <item>
      <title>How to group by calculated variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-group-by-calculated-variable/m-p/343957#M79003</link>
      <description>&lt;PRE&gt;rsubmit;
 data mytrans; 
 length TrYear 5
		  numMonth 3; 
 set db2dw.acarddet;
    TrYear = year(dTran);
		numMonth = month(dTran);
 run;
endrsubmit;
rsubmit;
proc sql;
 create table mnth_trans as
 select TrYear, numMonth, count(*) as tottxn from mytrans
 group by TrYear, numMonth;
;quit;
proc transreg data=mnth_trans;
   model identity(tottxn) = pbspline(TrYear); /* AICC criterion */
run;
endrsubmit;&lt;/PRE&gt;&lt;P&gt;What I'd like to do is combine the data step and proc sql in one procedure.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What's the best way to do so?&lt;/P&gt;&lt;P&gt;Or better yet, combine all data step proc sql and proc transgreg in 1 procedure...&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 04:14:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-group-by-calculated-variable/m-p/343957#M79003</guid>
      <dc:creator>afiqcjohari</dc:creator>
      <dc:date>2017-03-24T04:14:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by calculated variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-group-by-calculated-variable/m-p/343960#M79004</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/130031"&gt;@afiqcjohari&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;PRE&gt;rsubmit;
 data mytrans; 
 length TrYear 5
		  numMonth 3; 
 set db2dw.acarddet;
    TrYear = year(dTran);
		numMonth = month(dTran);
 run;
endrsubmit;
rsubmit;
proc sql;
 create table mnth_trans as
 select TrYear, numMonth, count(*) as tottxn from mytrans
 group by TrYear, numMonth;
;quit;
proc transreg data=mnth_trans;
   model identity(tottxn) = pbspline(TrYear); /* AICC criterion */
run;
endrsubmit;&lt;/PRE&gt;
&lt;P&gt;What I'd like to do is combine the data step and proc sql in one procedure.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What's the best way to do so?&lt;/P&gt;
&lt;P&gt;Or better yet, combine all data step proc sql and proc transgreg in 1 procedure...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Add the word CALCULATED before you use it in the GROUP (ie group by calculated trtYear, calculated trtMonth)&lt;/P&gt;
&lt;P&gt;Or use the calculation in the GROUP statement (ie group by year(date), month(date) )&lt;/P&gt;
&lt;P&gt;Or use a single PROC FREQ and format the date in the procedure.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table test as
select year(date) as Dyear, month(date) as DMonth, count(*) as Totalcount
from sashelp.stocks
group by calculated Dyear, calculated Dmonth;
quit;

proc sql;
create table test as
select year(date) as Dyear, month(date) as DMonth, count(*) as TotalCount
from sashelp.stocks
group by year(date), month(date);
quit;

proc freq data=sashelp.stocks noprint;
table date/out=want;
format date monyy7.;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 04:58:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-group-by-calculated-variable/m-p/343960#M79004</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-03-24T04:58:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by calculated variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-group-by-calculated-variable/m-p/343979#M79012</link>
      <description>The last solution is very interesting. Where can I learn more about using format in that way?</description>
      <pubDate>Fri, 24 Mar 2017 08:02:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-group-by-calculated-variable/m-p/343979#M79012</guid>
      <dc:creator>afiqcjohari</dc:creator>
      <dc:date>2017-03-24T08:02:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by calculated variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-group-by-calculated-variable/m-p/344048#M79035</link>
      <description>&lt;P&gt;You can read the article &lt;A href="http://blogs.sas.com/content/iml/2016/08/08/sas-formats-bin-numerical-variables.html" target="_self"&gt;"Use formats to bin numerical variables."&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Mar 2017 12:44:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-group-by-calculated-variable/m-p/344048#M79035</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2017-03-24T12:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by calculated variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-group-by-calculated-variable/m-p/344049#M79036</link>
      <description>&lt;P&gt;You can use the position in the column list in your GROUP BY phrase.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
 create table mnth_trans as
  select  year(dTran) as TrYear
       ,  month(dTran) as numMonth
       , count(*) as tottxn
   from mytrans
  group by 1,2
 ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Mar 2017 12:52:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-group-by-calculated-variable/m-p/344049#M79036</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-03-24T12:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to group by calculated variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-group-by-calculated-variable/m-p/344889#M79309</link>
      <description>This is terrific.</description>
      <pubDate>Tue, 28 Mar 2017 06:16:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-group-by-calculated-variable/m-p/344889#M79309</guid>
      <dc:creator>afiqcjohari</dc:creator>
      <dc:date>2017-03-28T06:16:22Z</dc:date>
    </item>
  </channel>
</rss>

