<?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 do I group dates in an Excel pivot table which derives from a SAS table? in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/615592#M18793</link>
    <description>&lt;P&gt;That's not really a pivot, that's just a summary on months and ID's.&lt;/P&gt;
&lt;P&gt;Start by creating a month column in the original data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Date :ddmmyy10. Product $ ID $;
format date yymmddd10.;
month = put(date,yymmd7.);
format date yymmddd10.;
datalines;
1/1/19 12345678 A
1/1/19 18656168 B 
2/1/19 13841388 A
2/1/19 18658779 B
15/1/19 16518464 A
18/1/19 18746351 B
10/2/19 18763156 A
19/3/19 18974631 A
25/3/19 19873210 A
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(note the data step with datalines to present data)&lt;/P&gt;
&lt;P&gt;Then, in SQL, create a lookup table containing all possible month/ID combinations, and then use that in a second step to create the wanted table:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table months as select distinct a.month, b.id
from have a, have b;
create table want as
select
  a.month, a.id, count(b.product) as count
from months a left join have b
on a.month = b.month and a.id = b.id
group by a.month, a.id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Output that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt; month     ID    count

2019-01    A       3  
2019-01    B       3  
2019-02    A       1  
2019-02    B       0  
2019-03    A       2  
2019-03    B       0  
&lt;/PRE&gt;
&lt;P&gt;Without the lookup table, we would not get those lines with a zero.&lt;/P&gt;</description>
    <pubDate>Tue, 07 Jan 2020 08:30:07 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-01-07T08:30:07Z</dc:date>
    <item>
      <title>How do I group dates in an Excel pivot table which derives from a SAS table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/614718#M18616</link>
      <description>&lt;P&gt;I used the SAS add-in tool to create a pivot table in Excel. However, I am unable to group dates together by months/years as the pivot recognises the dates as numeric values. The SAS table is from the SAS server and the date column is in a MMDDYY10. format.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2020 09:53:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/614718#M18616</guid>
      <dc:creator>ashlyn</dc:creator>
      <dc:date>2020-01-02T09:53:06Z</dc:date>
    </item>
    <item>
      <title>Re: How do I group dates in an Excel pivot table which derives from a SAS table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/614736#M18617</link>
      <description>&lt;P&gt;You have&amp;nbsp;&lt;STRONG&gt;SAS&lt;/STRONG&gt;. Do the pivot/transpose there.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Jan 2020 11:48:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/614736#M18617</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-02T11:48:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do I group dates in an Excel pivot table which derives from a SAS table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/615242#M18729</link>
      <description>&lt;P&gt;Hi KurtBremser, thanks for your input. However, I would like to remind you that there are many SAS users here of varying proficiency (I am very new to SAS), you do not have to be sarcastic. Hopefully everyone can create a healthy and welcoming environment here to learn SAS.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 03:25:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/615242#M18729</guid>
      <dc:creator>ashlyn</dc:creator>
      <dc:date>2020-01-06T03:25:00Z</dc:date>
    </item>
    <item>
      <title>Re: How do I group dates in an Excel pivot table which derives from a SAS table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/615263#M18735</link>
      <description>&lt;P&gt;Please give us an example of your source data in usable form (data step with datalines), and what you expect out of it, so that we can show you how to do it.&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2020 08:35:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/615263#M18735</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-06T08:35:13Z</dc:date>
    </item>
    <item>
      <title>Re: How do I group dates in an Excel pivot table which derives from a SAS table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/615579#M18786</link>
      <description>&lt;P&gt;I have a table which is updated on a weekly basis by the admin in the SAS server. I would like to create a pivot table in Excel which will be refreshed weekly when the table is updated. As I do not know how to pivot/transpose the data using SAS codes, I tried using the SAS add-in tool in Microsoft Excel to create the pivot table which gives me an issue in grouping dates in the pivot table.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 07:24:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/615579#M18786</guid>
      <dc:creator>ashlyn</dc:creator>
      <dc:date>2020-01-07T07:24:11Z</dc:date>
    </item>
    <item>
      <title>Re: How do I group dates in an Excel pivot table which derives from a SAS table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/615582#M18788</link>
      <description>&lt;P&gt;Please read my post again:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Please give us an example of your source data &lt;STRONG&gt;in usable form (data step with datalines)&lt;/STRONG&gt;, and &lt;STRONG&gt;what you expect out of it&lt;/STRONG&gt;, so that we can show you how to do it.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The intended outcome can be a screenshot, a listing, whatever. Burt please supply example data in a form that allows us to recreate it with a simple copy/paste and submit of the code.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;A mere repetition of your original problem description is not something we can work with.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 07:39:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/615582#M18788</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-07T07:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I group dates in an Excel pivot table which derives from a SAS table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/615583#M18789</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Date     Product ID Product
1/1/19   12345678  A
1/1/19   18656168  B 
2/1/19   13841388  A
2/1/19   18658779  B
15/1/19 16518464  A
18/1/19 18746351  B
10/2/19 18763156  A
19/3/19 18974631  A
25/3/19 19873210  A

         &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'm hoping to get a pivot table with the dates group by months and product, and the count.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jan 2019 Product A 3&lt;/P&gt;&lt;P&gt;Jan 2019 Product B 3&lt;/P&gt;&lt;P&gt;Feb 2019 Product A 1&lt;/P&gt;&lt;P&gt;Feb 2019 Product B 0&lt;/P&gt;&lt;P&gt;Mar 2019 Product A 2&lt;/P&gt;&lt;P&gt;Mar 2019 Product B 0&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 07:58:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/615583#M18789</guid>
      <dc:creator>ashlyn</dc:creator>
      <dc:date>2020-01-07T07:58:22Z</dc:date>
    </item>
    <item>
      <title>Re: How do I group dates in an Excel pivot table which derives from a SAS table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/615592#M18793</link>
      <description>&lt;P&gt;That's not really a pivot, that's just a summary on months and ID's.&lt;/P&gt;
&lt;P&gt;Start by creating a month column in the original data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Date :ddmmyy10. Product $ ID $;
format date yymmddd10.;
month = put(date,yymmd7.);
format date yymmddd10.;
datalines;
1/1/19 12345678 A
1/1/19 18656168 B 
2/1/19 13841388 A
2/1/19 18658779 B
15/1/19 16518464 A
18/1/19 18746351 B
10/2/19 18763156 A
19/3/19 18974631 A
25/3/19 19873210 A
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(note the data step with datalines to present data)&lt;/P&gt;
&lt;P&gt;Then, in SQL, create a lookup table containing all possible month/ID combinations, and then use that in a second step to create the wanted table:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table months as select distinct a.month, b.id
from have a, have b;
create table want as
select
  a.month, a.id, count(b.product) as count
from months a left join have b
on a.month = b.month and a.id = b.id
group by a.month, a.id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Output that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt; month     ID    count

2019-01    A       3  
2019-01    B       3  
2019-02    A       1  
2019-02    B       0  
2019-03    A       2  
2019-03    B       0  
&lt;/PRE&gt;
&lt;P&gt;Without the lookup table, we would not get those lines with a zero.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 08:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/615592#M18793</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-07T08:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do I group dates in an Excel pivot table which derives from a SAS table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/615595#M18796</link>
      <description>&lt;P&gt;Thanks for the solution. However, I literally need a pivot table in Microsoft Excel that is linked to the SAS table. This Excel file will be shared across multiple parties and having the pivot table can allow parties to get the different variables they need (which are not shown in the example above). The variables I mentioned above will form the main pivot table that the users can see when they open the Excel file.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The SAS Add-in tool solved my initial problem in creating the pivot table in Excel but I am just stuck at grouping dates into months. Hope my question is clear.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Jan 2020 08:41:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/615595#M18796</guid>
      <dc:creator>ashlyn</dc:creator>
      <dc:date>2020-01-07T08:41:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do I group dates in an Excel pivot table which derives from a SAS table?</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/615601#M18798</link>
      <description>&lt;P&gt;My post shows how to create a month variable from the dates. Use that in Excel.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;month = put(date,yymmd7.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jan 2020 09:06:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-group-dates-in-an-Excel-pivot-table-which-derives-from/m-p/615601#M18798</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-01-07T09:06:11Z</dc:date>
    </item>
  </channel>
</rss>

