<?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: About Group_by aggregation functions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702145#M215072</link>
    <description>&lt;P&gt;Thanks for your reply! I just change my coding like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cus_tran;
	input  ID AGE $5. GENDER $ SUB_NUM TRANSACTION_DATE :yymmdd10. QUANTITY Profit;
	format TRANSACTION_DATE yymmdd10.;
	Datalines;
	1 10-19 F 0 2014-05-06 1 13
	1 10-19	F 1 2014-05-06 1 13
	1 10-19 F 1 2014-04-10 2 22
	2 10-19 M 1 2014-04-11 2 10
	3 30-40 F 1 2014-04-07 1 10
	4 10-19 F 0 2014-04-08 1 10
	3 30-40 F 0 2014-04-22 1 20
	5 20-30 M 1 2014-04-30 1 20
	2 10-19 M 0 2014-05-01 1 20
	3 30-40 F 0 2014-05-06 1 10
	4 10-19 F 1 2014-05-10 3 20
	4 10-19 F 0 2014-04-30 1 20
	5 20-30 M 1 2014-05-10 1 20
	2 10-19 M 0 2014-05-10 1 30
	3 30-40 F 0 2014-05-01 1 10
	2 10-19 M 1 2014-04-01 1 10
	3 30-40 F 1 2014-05-01 1 20
	;
RUN;

proc sql;
   create table want as
	SELECT  ID,put(TRANSACTION_DATE,monyy7.) as month_year, sum (Profit) as totalProfit, count (QUANTITY) as totalQuantity, 
			sum (SUB_NUM) as frequency, GENDER, AGE
	From cus_tran
	Group By ID, month_year;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, the outcome is like the following. Now the data is not grouped by each specific ID. Can you please help me fix this? I just wonder can I use duplicate function? But that is for the duplicate row, not for specific duplicated cell. Can you help me? Thanks so much!&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jianan_luna_0-1606528668159.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/52059i5582A30C5B3FA481/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jianan_luna_0-1606528668159.png" alt="Jianan_luna_0-1606528668159.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 28 Nov 2020 02:00:53 GMT</pubDate>
    <dc:creator>Jianan_luna</dc:creator>
    <dc:date>2020-11-28T02:00:53Z</dc:date>
    <item>
      <title>About Group  By</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/701966#M214985</link>
      <description>&lt;P&gt;Recently, I am working on prediction for one dataset(for a store). I want to use group_by function to conclude some attributes. But my goal is a little complicated, because I want to separate the data into April and May.&lt;/P&gt;
&lt;P&gt;For each specific customer(CUSTOMER_ID):&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Profit, AGE, GENDER for each customer in April&lt;/LI&gt;
&lt;LI&gt;QUANTITY purchased by each customer in April&lt;/LI&gt;
&lt;LI&gt;I count TRANSACTION_DATE to find the how many times each customers come to store in April&lt;/LI&gt;
&lt;LI&gt;SUB_NUM means whether the customers purchase certain product, I use 1 represent the customer purchased it, 0 represents they don't. Here, my goal is: for each customer, did they purchase it on April, and did they purchase it on May, so basically, it's two columns. Here is the most confused point.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;The my desired outcome is like this, for each specific customer, I can conclude:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="14.285714285714286%"&gt;customer_id&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;gender&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;age&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;sub_num on April&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;sub_num on May&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;Quantity purchased on April&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;sum of "transaction_date" on April&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="14.285714285714286%"&gt;1&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="14.285714285714286%"&gt;2&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="14.285714285714286%"&gt;3&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;here is the coding I have&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	SELECT  customer_ID, sum (Profit) as totalProfit, count (QUANTITY) as totalQuantity,  count (TRANSACTION_DATE) as frequency,  
	From cus_tran
	where TRANSACTION_DATE &amp;lt; "01MAY2014"d
	Group By customer_ID;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I am confused, because I want to group each specific customers, and conclude several data only on April, one only on May, and combine those dataset in one table. I think where clause is not available here, if only focus on April data, the data is likely to become incomplete, thus I cannot got data for each customers. I spend a so hard time on it, can you please help me fix it? Thanks so much!&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2020 07:06:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/701966#M214985</guid>
      <dc:creator>Jianan_luna</dc:creator>
      <dc:date>2020-11-27T07:06:22Z</dc:date>
    </item>
    <item>
      <title>Re: About Group  By</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/701967#M214986</link>
      <description>&lt;P&gt;Can you please post the data you have in usable form? This is a data step using datalines.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2020 07:29:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/701967#M214986</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-11-27T07:29:42Z</dc:date>
    </item>
    <item>
      <title>Re: About Group By</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/701968#M214987</link>
      <description>Sorry, can you please let me know what kind of data type you are looking&lt;BR /&gt;for? I didn’t make sense&lt;BR /&gt;</description>
      <pubDate>Fri, 27 Nov 2020 07:54:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/701968#M214987</guid>
      <dc:creator>Jianan_luna</dc:creator>
      <dc:date>2020-11-27T07:54:57Z</dc:date>
    </item>
    <item>
      <title>Re: About Group By</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/701971#M214988</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/336146"&gt;@Jianan_luna&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Sorry, can you please let me know what kind of data type you are looking&lt;BR /&gt;for? I didn’t make sense&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;To be able to suggest something useful, i need to see data you have.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2020 08:12:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/701971#M214988</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-11-27T08:12:19Z</dc:date>
    </item>
    <item>
      <title>Re: About Group By</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/701973#M214989</link>
      <description>I post the attachment “cus_tran_sas.xlsx” under my question. Please check it</description>
      <pubDate>Fri, 27 Nov 2020 08:19:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/701973#M214989</guid>
      <dc:creator>Jianan_luna</dc:creator>
      <dc:date>2020-11-27T08:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: About Group By</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/701976#M214990</link>
      <description>&lt;P&gt;Excel spreadsheets are mostly useless in representing SAS datasets. Excel does not have the concept of fixed columns attributes, so we can not infer types, sizes, and formats from an Excel spreadsheet.&lt;/P&gt;
&lt;P&gt;On top of that, many corporate environments block the download of Office files in their proxies and firewalls, because of security aspects. MS Office files are the #1 vector for malware attacks.&lt;/P&gt;
&lt;P&gt;A data step with datalines, on the other hand, is just text and therefore no security concern at all. And it takes just a simple copy/paste of the code to our program editor and a submit to create an exact replica of your dataset, while Excel files force us to download and then import them, with quite unreliable and unpredictable results.&lt;/P&gt;
&lt;P&gt;Creating such a data step with datalines is no rocket science (even people of limited intelligence, like myself, have mastered it), but a very useful SAS skill that SAS newcomers should learn to use right at the beginning. Creating fake data for testing is a necessary tool for your SAS toolbox.&lt;/P&gt;</description>
      <pubDate>Fri, 27 Nov 2020 08:45:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/701976#M214990</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-27T08:45:32Z</dc:date>
    </item>
    <item>
      <title>Re: About Group By</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702084#M215030</link>
      <description>&lt;P&gt;Thanks so much Sir, I think I got it. I create a code like this, please check it&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data cus_tran;
	input  ID AGE $5. GENDER $ SUB_NUM TRANSACTION_DATE $10. QUANTITY Profit;
	Datalines;
	1 10-19 F 0 2014-05-06 1 13
	1 10-19	F 1 2014-05-06 1 13
	1 10-19 F 1 2014-04-10 2 22
	2 10-19 M 1 2014-04-11 2 10
	3 30-40 F 1 2014-04-07 1 10
	4 10-19 F 0 2014-04-08 1 10
	3 30-40 F 0 2014-04-22 1 20
	5 20-30 M 1 2014-04-30 1 20
	2 10-19 M 0 2014-05-01 1 20
	3 30-40 F 0 2014-05-06 1 10
	4 10-19 F 1 2014-05-10 3 20
	4 10-19 F 0 2014-04-30 1 20
	5 20-30 M 1 2014-05-10 1 20
	2 10-19 M 0 2014-05-10 1 30
	3 30-40 F 0 2014-05-01 1 10
	2 10-19 M 1 2014-04-01 1 10
	3 30-40 F 1 2014-05-01 1 20
	;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Nov 2020 18:15:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702084#M215030</guid>
      <dc:creator>Jianan_luna</dc:creator>
      <dc:date>2020-11-27T18:15:44Z</dc:date>
    </item>
    <item>
      <title>Re: About Group By</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702085#M215031</link>
      <description>&lt;P&gt;Thanks so much, here is the dataline I created, please check:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data cus_tran;
	input  ID AGE $5. GENDER $ SUB_NUM TRANSACTION_DATE $10. QUANTITY Profit;
	Datalines;
	1 10-19 F 0 2014-05-06 1 13
	1 10-19	F 1 2014-05-06 1 13
	1 10-19 F 1 2014-04-10 2 22
	2 10-19 M 1 2014-04-11 2 10
	3 30-40 F 1 2014-04-07 1 10
	4 10-19 F 0 2014-04-08 1 10
	3 30-40 F 0 2014-04-22 1 20
	5 20-30 M 1 2014-04-30 1 20
	2 10-19 M 0 2014-05-01 1 20
	3 30-40 F 0 2014-05-06 1 10
	4 10-19 F 1 2014-05-10 3 20
	4 10-19 F 0 2014-04-30 1 20
	5 20-30 M 1 2014-05-10 1 20
	2 10-19 M 0 2014-05-10 1 30
	3 30-40 F 0 2014-05-01 1 10
	2 10-19 M 1 2014-04-01 1 10
	3 30-40 F 1 2014-05-01 1 20
	;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 Nov 2020 18:16:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702085#M215031</guid>
      <dc:creator>Jianan_luna</dc:creator>
      <dc:date>2020-11-27T18:16:23Z</dc:date>
    </item>
    <item>
      <title>About Group_by aggregation functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702132#M215066</link>
      <description>&lt;P&gt;I am using GROUP_BY to aggregate some variables. My goal is group by ID, then SUM the "Profit" only on April, COUNT the "Quantity" only on April, SUM the "SUB_NUM" only on May. I tried to find how to use IF function in aggregation, but I didn't find it. Could you please help me figure it out? Here is the dataset and my coding.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cus_tran;
	input  ID AGE $5. GENDER $ SUB_NUM TRANSACTION_DATE $10. QUANTITY Profit;
	Datalines;
	1 10-19 F 0 2014-05-06 1 13
	1 10-19	F 1 2014-05-06 1 13
	1 10-19 F 1 2014-04-10 2 22
	2 10-19 M 1 2014-04-11 2 10
	3 30-40 F 1 2014-04-07 1 10
	4 10-19 F 0 2014-04-08 1 10
	3 30-40 F 0 2014-04-22 1 20
	5 20-30 M 1 2014-04-30 1 20
	2 10-19 M 0 2014-05-01 1 20
	3 30-40 F 0 2014-05-06 1 10
	4 10-19 F 1 2014-05-10 3 20
	4 10-19 F 0 2014-04-30 1 20
	5 20-30 M 1 2014-05-10 1 20
	2 10-19 M 0 2014-05-10 1 30
	3 30-40 F 0 2014-05-01 1 10
	2 10-19 M 1 2014-04-01 1 10
	3 30-40 F 1 2014-05-01 1 20
	;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
	SELECT  ID, sum (Profit) as totalProfit, count (QUANTITY) as totalQuantity, 
			sum (SUB_NUM) as frequency 
	From cus_tran
	Group By ID;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This is my coding, but it includes all data from both April and May, can you please help me separate it? Thanks so much!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sincerely,&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Sat, 28 Nov 2020 00:43:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702132#M215066</guid>
      <dc:creator>Jianan_luna</dc:creator>
      <dc:date>2020-11-28T00:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: About Group_by aggregation functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702134#M215067</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;


data cus_tran;
	input  ID AGE $5. GENDER $ SUB_NUM TRANSACTION_DATE :yymmdd10. QUANTITY Profit;
	format TRANSACTION_DATE yymmdd10.;
	Datalines;
	1 10-19 F 0 2014-05-06 1 13
	1 10-19	F 1 2014-05-06 1 13
	1 10-19 F 1 2014-04-10 2 22
	2 10-19 M 1 2014-04-11 2 10
	3 30-40 F 1 2014-04-07 1 10
	4 10-19 F 0 2014-04-08 1 10
	3 30-40 F 0 2014-04-22 1 20
	5 20-30 M 1 2014-04-30 1 20
	2 10-19 M 0 2014-05-01 1 20
	3 30-40 F 0 2014-05-06 1 10
	4 10-19 F 1 2014-05-10 3 20
	4 10-19 F 0 2014-04-30 1 20
	5 20-30 M 1 2014-05-10 1 20
	2 10-19 M 0 2014-05-10 1 30
	3 30-40 F 0 2014-05-01 1 10
	2 10-19 M 1 2014-04-01 1 10
	3 30-40 F 1 2014-05-01 1 20
	;
RUN;

proc sql;
   create table want as
	SELECT  ID,put(TRANSACTION_DATE,monyy7.) as month_year, sum (Profit) as totalProfit, count (QUANTITY) as totalQuantity, 
			sum (SUB_NUM) as frequency 
	From cus_tran
	Group By ID,month_year;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 28 Nov 2020 00:50:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702134#M215067</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-11-28T00:50:35Z</dc:date>
    </item>
    <item>
      <title>Re: About Group_by aggregation functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702138#M215068</link>
      <description>&lt;P&gt;Thanks so much, but when I run the coding, it shows errors in log. The error is like following: the TRANSACTION_DATE should be numeric, but actually it's a character type. Could you please help me fix it? Thanks so much again!&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jianan_luna_0-1606525576218.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/52057i3549EF113A54E5CA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jianan_luna_0-1606525576218.png" alt="Jianan_luna_0-1606525576218.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Nov 2020 01:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702138#M215068</guid>
      <dc:creator>Jianan_luna</dc:creator>
      <dc:date>2020-11-28T01:07:43Z</dc:date>
    </item>
    <item>
      <title>Re: About Group_by aggregation functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702139#M215069</link>
      <description>&lt;P&gt;The code from &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; changes the INPUT statement to make transaction_date numeric. In general, if something is a date (or time or date-time) then you really ought to input it as numeric. There is no value in making dates or times character and huge benefits to making it numeric.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Nov 2020 01:11:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702139#M215069</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-28T01:11:55Z</dc:date>
    </item>
    <item>
      <title>Re: About Group_by aggregation functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702140#M215070</link>
      <description>&lt;P&gt;Thanks so much Sir! I want to get the corresponding gender and age for every ID. I add gender and age after SELECT clause, but when I added it, then it the ID is not grouped at all. like this:&lt;/P&gt;
&lt;P&gt;Is there any way to get the corresponding age and gender for everyone with Group_by function. Thanks so much. Here is my coding:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cus_tran;
	input  ID AGE $5. GENDER $ SUB_NUM TRANSACTION_DATE :yymmdd10. QUANTITY Profit;
	format TRANSACTION_DATE yymmdd10.;
	Datalines;
	1 10-19 F 0 2014-05-06 1 13
	1 10-19	F 1 2014-05-06 1 13
	1 10-19 F 1 2014-04-10 2 22
	2 10-19 M 1 2014-04-11 2 10
	3 30-40 F 1 2014-04-07 1 10
	4 10-19 F 0 2014-04-08 1 10
	3 30-40 F 0 2014-04-22 1 20
	5 20-30 M 1 2014-04-30 1 20
	2 10-19 M 0 2014-05-01 1 20
	3 30-40 F 0 2014-05-06 1 10
	4 10-19 F 1 2014-05-10 3 20
	4 10-19 F 0 2014-04-30 1 20
	5 20-30 M 1 2014-05-10 1 20
	2 10-19 M 0 2014-05-10 1 30
	3 30-40 F 0 2014-05-01 1 10
	2 10-19 M 1 2014-04-01 1 10
	3 30-40 F 1 2014-05-01 1 20
	;
RUN;

proc sql;
   create table want as
	SELECT  ID,put(TRANSACTION_DATE,monyy7.) as month_year, sum (Profit) as totalProfit, count (QUANTITY) as totalQuantity, 
			sum (SUB_NUM) as frequency, GENDER, AGE 
	From cus_tran
	Group By ID,GENDER,AGE,month_year;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 28 Nov 2020 01:41:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702140#M215070</guid>
      <dc:creator>Jianan_luna</dc:creator>
      <dc:date>2020-11-28T01:41:04Z</dc:date>
    </item>
    <item>
      <title>Re: About Group_by aggregation functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702142#M215071</link>
      <description>Since you have gender and age in the SELECT clause, you should not put those variables in the GROUP BY clause.</description>
      <pubDate>Sat, 28 Nov 2020 01:50:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702142#M215071</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-28T01:50:11Z</dc:date>
    </item>
    <item>
      <title>About Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702143#M215064</link>
      <description>&lt;P&gt;I just got a result table like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jianan_luna_0-1606528193752.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/52058iB6E7EAE48E864DC0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jianan_luna_0-1606528193752.png" alt="Jianan_luna_0-1606528193752.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;However, I want to edit my layout like this: for each specific customers, their corresponding age and gender, with total_profit/total_quantity, frequency on April, frequency on May, and with their gender and age. I am trying TRANSPOSE, however, I failed to transpose it. Could you please help me fix this? I put my coding following with this table as well. Thanks so much!&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="14.285714285714286%" height="57px"&gt;ID&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="57px"&gt;total_profit only in April&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="57px"&gt;total quantity (only on April)&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="57px"&gt;frequency (only on April)&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="57px"&gt;frequency (only on May)&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="57px"&gt;gender&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="57px"&gt;age&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="14.285714285714286%" height="29px"&gt;1&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="29px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="29px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="29px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="29px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="29px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="29px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="14.285714285714286%" height="29px"&gt;2&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="29px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="29px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="29px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="29px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="29px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="29px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cus_tran;
	input  ID AGE $5. GENDER $ SUB_NUM TRANSACTION_DATE :yymmdd10. QUANTITY Profit;
	format TRANSACTION_DATE yymmdd10.;
	Datalines;
	1 10-19 F 0 2014-05-06 1 13
	1 10-19	F 1 2014-05-06 1 13
	1 10-19 F 1 2014-04-10 2 22
	2 10-19 M 1 2014-04-11 2 10
	3 30-40 F 1 2014-04-07 1 10
	4 10-19 F 0 2014-04-08 1 10
	3 30-40 F 0 2014-04-22 1 20
	5 20-30 M 1 2014-04-30 1 20
	2 10-19 M 0 2014-05-01 1 20
	3 30-40 F 0 2014-05-06 1 10
	4 10-19 F 1 2014-05-10 3 20
	4 10-19 F 0 2014-04-30 1 20
	5 20-30 M 1 2014-05-10 1 20
	2 10-19 M 0 2014-05-10 1 30
	3 30-40 F 0 2014-05-01 1 10
	2 10-19 M 1 2014-04-01 1 10
	3 30-40 F 1 2014-05-01 1 20
	;
RUN;

proc sql;
   create table want as
	SELECT  ID,put(TRANSACTION_DATE,monyy7.) as month_year, sum (Profit) as totalProfit, count (QUANTITY) as totalQuantity, 
			sum (SUB_NUM) as frequency
	From cus_tran
	Group By ID,month_year;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Nov 2020 01:55:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702143#M215064</guid>
      <dc:creator>Jianan_luna</dc:creator>
      <dc:date>2020-11-28T01:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: About Group_by aggregation functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702145#M215072</link>
      <description>&lt;P&gt;Thanks for your reply! I just change my coding like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data cus_tran;
	input  ID AGE $5. GENDER $ SUB_NUM TRANSACTION_DATE :yymmdd10. QUANTITY Profit;
	format TRANSACTION_DATE yymmdd10.;
	Datalines;
	1 10-19 F 0 2014-05-06 1 13
	1 10-19	F 1 2014-05-06 1 13
	1 10-19 F 1 2014-04-10 2 22
	2 10-19 M 1 2014-04-11 2 10
	3 30-40 F 1 2014-04-07 1 10
	4 10-19 F 0 2014-04-08 1 10
	3 30-40 F 0 2014-04-22 1 20
	5 20-30 M 1 2014-04-30 1 20
	2 10-19 M 0 2014-05-01 1 20
	3 30-40 F 0 2014-05-06 1 10
	4 10-19 F 1 2014-05-10 3 20
	4 10-19 F 0 2014-04-30 1 20
	5 20-30 M 1 2014-05-10 1 20
	2 10-19 M 0 2014-05-10 1 30
	3 30-40 F 0 2014-05-01 1 10
	2 10-19 M 1 2014-04-01 1 10
	3 30-40 F 1 2014-05-01 1 20
	;
RUN;

proc sql;
   create table want as
	SELECT  ID,put(TRANSACTION_DATE,monyy7.) as month_year, sum (Profit) as totalProfit, count (QUANTITY) as totalQuantity, 
			sum (SUB_NUM) as frequency, GENDER, AGE
	From cus_tran
	Group By ID, month_year;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, the outcome is like the following. Now the data is not grouped by each specific ID. Can you please help me fix this? I just wonder can I use duplicate function? But that is for the duplicate row, not for specific duplicated cell. Can you help me? Thanks so much!&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Jianan_luna_0-1606528668159.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/52059i5582A30C5B3FA481/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Jianan_luna_0-1606528668159.png" alt="Jianan_luna_0-1606528668159.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 28 Nov 2020 02:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702145#M215072</guid>
      <dc:creator>Jianan_luna</dc:creator>
      <dc:date>2020-11-28T02:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: About Group By</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702166#M215055</link>
      <description>&lt;P&gt;So we are interested in dates of April and May 2014. The WHERE should look like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where '01apr2014'd le transaction_date le '31may2014'd&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since you want age and gender in the result, you need to have them in the GROUP BY&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;group by customer_id, age, gender&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To build a conditional sum, use a combination of the summary function and CASE&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;sum(case when transaction_date lt '01may2014'd then sub_num else 0 end) as sub_num_april&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;From these blocks, you should be able to build your query.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Nov 2020 08:44:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702166#M215055</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-28T08:44:26Z</dc:date>
    </item>
    <item>
      <title>Re: About Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702187#M215065</link>
      <description>&lt;P&gt;Let's translate the table headers into an SQL query.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;select 
   ID
  ,sum(case when month(transaction_date)=4 then profit else . end)
     as total_profit_only_in_April
  ,sum(case when month(transaction_date)=4 then quantity else . end)
     as total_quantity_only_in_April
  ,count(case when month(transaction_date)=4 then quantity else . end)
     as frequency_only_in_April
  ,count(case when month(transaction_date)=5 then quantity else . end)
     as frequency_only_in_May
  ,max(gender) as gender
  ,max(age) as age
from cus_tran
group by id 
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 28 Nov 2020 15:56:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702187#M215065</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-11-28T15:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: About Group_by aggregation functions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702189#M215073</link>
      <description>&lt;P&gt;I have merged all your posts that deal with the same issue into the original thread. Please keep one question in in one thread.&lt;/P&gt;</description>
      <pubDate>Sat, 28 Nov 2020 16:15:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702189#M215073</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-11-28T16:15:25Z</dc:date>
    </item>
    <item>
      <title>Re: About Transpose</title>
      <link>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702198#M215075</link>
      <description>Thanks so much</description>
      <pubDate>Sat, 28 Nov 2020 17:32:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/About-Group-By/m-p/702198#M215075</guid>
      <dc:creator>Jianan_luna</dc:creator>
      <dc:date>2020-11-28T17:32:24Z</dc:date>
    </item>
  </channel>
</rss>

