<?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: Count on multiple dates! Help. in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304393#M20633</link>
    <description>&lt;P&gt;Are you coding or using the GUI in EG?&lt;/P&gt;</description>
    <pubDate>Thu, 13 Oct 2016 15:28:08 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-10-13T15:28:08Z</dc:date>
    <item>
      <title>Count on multiple dates! Help.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304391#M20632</link>
      <description>&lt;P&gt;Hi.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dates in the following format. 01JAN2016:12:00:00 (datetime21)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my example I have 2 columns. One with dates and the other one with Car Models.&amp;nbsp;&lt;BR /&gt;I need to find out all the Nissans that were purchases in Jan, Feb, March, etc ( for the entire year). separated by month.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using PROC SQL;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how do i create a query to give me an output that will show&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Column 1: Months &amp;nbsp;Column 2: Car_Models&lt;/P&gt;
&lt;P&gt;Table: January 50&lt;/P&gt;
&lt;P&gt;February 80&amp;nbsp;&lt;/P&gt;
&lt;P&gt;etc.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2016 15:26:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304391#M20632</guid>
      <dc:creator>itshere</dc:creator>
      <dc:date>2016-10-13T15:26:06Z</dc:date>
    </item>
    <item>
      <title>Re: Count on multiple dates! Help.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304393#M20633</link>
      <description>&lt;P&gt;Are you coding or using the GUI in EG?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2016 15:28:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304393#M20633</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-13T15:28:08Z</dc:date>
    </item>
    <item>
      <title>Re: Count on multiple dates! Help.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304397#M20635</link>
      <description>&lt;P&gt;data out;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;set in;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; month=month(date);****Use your datetime variable here and extract month using month ();&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; create table out1 as&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select a.month,a.carmodel&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;from out as a&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;group by month;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;I hope this will be useful.&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;&lt;P&gt;&amp;nbsp;&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>Thu, 13 Oct 2016 15:41:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304397#M20635</guid>
      <dc:creator>skg74_mail_umkc_edu</dc:creator>
      <dc:date>2016-10-13T15:41:37Z</dc:date>
    </item>
    <item>
      <title>Re: Count on multiple dates! Help.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304400#M20636</link>
      <description>&lt;P&gt;just coding, creating a query to extract from an already existing table.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2016 15:44:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304400#M20636</guid>
      <dc:creator>itshere</dc:creator>
      <dc:date>2016-10-13T15:44:42Z</dc:date>
    </item>
    <item>
      <title>Re: Count on multiple dates! Help.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304402#M20638</link>
      <description>How do i tell Sas to categorize all January dates form 1 to 31 as JANUARY.. and so on for the other months..</description>
      <pubDate>Thu, 13 Oct 2016 15:47:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304402#M20638</guid>
      <dc:creator>itshere</dc:creator>
      <dc:date>2016-10-13T15:47:08Z</dc:date>
    </item>
    <item>
      <title>Re: Count on multiple dates! Help.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304403#M20639</link>
      <description>You want to categorize based on months rite? Month function will help to extract the month value.It is a function.</description>
      <pubDate>Thu, 13 Oct 2016 15:49:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304403#M20639</guid>
      <dc:creator>skg74_mail_umkc_edu</dc:creator>
      <dc:date>2016-10-13T15:49:21Z</dc:date>
    </item>
    <item>
      <title>Re: Count on multiple dates! Help.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304407#M20641</link>
      <description>&lt;P&gt;Proc SQL;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;create table want as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;select year(datepart(datetime)) as year,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Month(datepart(datetime)) as month,&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Coumt(*) as count&lt;/P&gt;
&lt;P&gt;From have&lt;/P&gt;
&lt;P&gt;group by calculated year, calculated month;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;because,you have a datetime variable first use the datepart() function to get a date and then month/year to get the month/year.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wasn't sure if you wanted year or not so included it but you can remove it if desired.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2016 15:55:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304407#M20641</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-13T15:55:08Z</dc:date>
    </item>
    <item>
      <title>Re: Count on multiple dates! Help.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304412#M20644</link>
      <description>&lt;P&gt;proc sql;&lt;BR /&gt;create table months as&lt;BR /&gt;select year(datepart(purchase_time) as year,Month(datepart(purchase_time) as month,&lt;BR /&gt;Count(*) as count&lt;BR /&gt;From workbook1&lt;BR /&gt;where model = "Nissan"&lt;BR /&gt;group by year, month, model&lt;BR /&gt;quit;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Oct 2016 16:07:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304412#M20644</guid>
      <dc:creator>skg74_mail_umkc_edu</dc:creator>
      <dc:date>2016-10-13T16:07:21Z</dc:date>
    </item>
    <item>
      <title>Re: Count on multiple dates! Help.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304414#M20645</link>
      <description>So I did this and it worked but the results showed as MONTH column and the rows were 1-9.  What does that mean? My dates vary from 2015 to 2016. I need to capture only 2016 and would need it to say Jan, feb, etc, for just 2016.. how do i include it to say Jan 2016, feb 2016, etc&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table months as &lt;BR /&gt;select Month(datepart(purchase_time) as month,&lt;BR /&gt;Count(*) as count&lt;BR /&gt;From workbook1&lt;BR /&gt;where model = "Nissan"&lt;BR /&gt;group by month, model;&lt;BR /&gt;quit;</description>
      <pubDate>Thu, 13 Oct 2016 16:12:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304414#M20645</guid>
      <dc:creator>itshere</dc:creator>
      <dc:date>2016-10-13T16:12:34Z</dc:date>
    </item>
    <item>
      <title>Re: Count on multiple dates! Help.</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304455#M20650</link>
      <description>&lt;P&gt;Key concepts:&lt;/P&gt;
&lt;P&gt;Date vs Datetime and how to convert between them -&amp;gt; DATEPART()&lt;/P&gt;
&lt;P&gt;Apply Formats to get desired format -&amp;gt; PUT()&lt;/P&gt;
&lt;P&gt;Format dates -&amp;gt; MONYY7.&lt;/P&gt;
&lt;P&gt;Extracting components of a date -&amp;gt; MONTH() /YEAR() functions&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The Month() will calculate&amp;nbsp;a month, but all January's will be combined. So January 2016 is the same as January 2015.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The month function returns the month a 1-12 where 1 corresponds to January and 12 to December.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of SQL I recommend a proc means as it will accept formats so you don't have to do too much data conversion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have1;
set have;

date=datepart(datetime);
run;

proc means data=have N;
class date;
format date monyy7.;
var amount;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or modified SQL if you choose to stick with SQL:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;&lt;BR /&gt;select put(datepart(datetime), monyy7.) as Year_Char, 
           Count(*) as count
From have&lt;BR /&gt;where year(datepart(datetime))=2016
group by calculated year_Char;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 13 Oct 2016 19:22:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Count-on-multiple-dates-Help/m-p/304455#M20650</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-10-13T19:22:29Z</dc:date>
    </item>
  </channel>
</rss>

