<?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: DateTime group by in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/DateTime-group-by/m-p/138355#M37127</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't see a summary function so you likely want to use ORDER BY instead of GROUP BY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ORDER BY datepart(start)&lt;/P&gt;&lt;P&gt;should get you there instead of GROUP BY Start&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 05 Dec 2014 17:50:10 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2014-12-05T17:50:10Z</dc:date>
    <item>
      <title>DateTime group by</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DateTime-group-by/m-p/138354#M37126</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;BR /&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have some data where the date is datetime, I am attempting to do a datepart so as to group by.&lt;/P&gt;&lt;P&gt;Please see below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql exec; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; connect to sqlservr as Sstats (server= xxxxx database=Source_B); &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; create table test as select date,count(status)as Totals &lt;BR /&gt; &lt;BR /&gt;from connection to sstats(&lt;BR /&gt;SELECT datepart(start)format weekdate17. as date,status&lt;/P&gt;&lt;P&gt;FROM [Table]&lt;BR /&gt;group by start)&lt;BR /&gt;where (START)&amp;gt;= &amp;amp;fromdate&lt;BR /&gt;and (START) &amp;lt; &amp;amp;todate ;&lt;BR /&gt;disconnect from sStats; &lt;BR /&gt;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; quit; run; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Help please.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Fred&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Dec 2014 17:12:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DateTime-group-by/m-p/138354#M37126</guid>
      <dc:creator>fred_major</dc:creator>
      <dc:date>2014-12-05T17:12:08Z</dc:date>
    </item>
    <item>
      <title>Re: DateTime group by</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DateTime-group-by/m-p/138355#M37127</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I don't see a summary function so you likely want to use ORDER BY instead of GROUP BY.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ORDER BY datepart(start)&lt;/P&gt;&lt;P&gt;should get you there instead of GROUP BY Start&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Dec 2014 17:50:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DateTime-group-by/m-p/138355#M37127</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-12-05T17:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: DateTime group by</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DateTime-group-by/m-p/138356#M37128</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;/P&gt;&lt;P&gt;It is actually reads count(status)as Totals&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need it to give me the total count by date, i'm not clear on how to do this when field is datetime.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Fred&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Dec 2014 17:56:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DateTime-group-by/m-p/138356#M37128</guid>
      <dc:creator>fred_major</dc:creator>
      <dc:date>2014-12-05T17:56:25Z</dc:date>
    </item>
    <item>
      <title>Re: DateTime group by</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DateTime-group-by/m-p/138357#M37129</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;missed that I was having a hard time reading with the way the code was shown.&lt;/P&gt;&lt;P&gt;Group by datepart(start) should work&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Dec 2014 18:05:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DateTime-group-by/m-p/138357#M37129</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-12-05T18:05:56Z</dc:date>
    </item>
    <item>
      <title>Re: DateTime group by</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DateTime-group-by/m-p/138358#M37130</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Using datepart() to convert to a date in SAS SQL is one way. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You're using pass through code though, so your code needs to be SQL compliant not SAS compliant, so the datepart function possibly won't work the same on the server. Find the appropriate function on SQL, most likely a variant on the convert() function. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Dec 2014 18:06:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DateTime-group-by/m-p/138358#M37130</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-12-05T18:06:48Z</dc:date>
    </item>
    <item>
      <title>Re: DateTime group by</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DateTime-group-by/m-p/138359#M37131</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You haven't posted valid SQL code. You are using SAS syntax like datepart() in the code section for explicit SQL Server code - so this can't work. You're then having a "group by" in this section as well but the summary function "&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;count(status) as Totals &lt;/SPAN&gt;" is outside on the SAS side. This can't work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's may be easier for you to first write your SQL query in SAS syntax (using implicit SQL) and only when this works and you need to improve performance, amend to code to run as explicit SQL.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;OPTIONS SASTRACE=',,,d' SASTRACELOC=SASLOG NOSTSUFFIX;&lt;/P&gt;&lt;P&gt;libname mydata &amp;lt;definitions for SQL db &amp;gt; ;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql exec;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table test as&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; select&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; datepart(start) as date format=weekdate17. ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count(status)as Totals&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FROM mydata.[Table]&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where (START)&amp;gt;= &amp;amp;fromdate and (START) &amp;lt; &amp;amp;todate&amp;nbsp;&amp;nbsp; /* assumes macro vars contain datetime values, else use datepart() as well */&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; group by datepart(start)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Dec 2014 18:14:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DateTime-group-by/m-p/138359#M37131</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-12-05T18:14:55Z</dc:date>
    </item>
    <item>
      <title>Re: DateTime group by</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/DateTime-group-by/m-p/138360#M37132</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes sorry I understand that my code was all over the place, I attempted all different things in an effort before submitting my post.&lt;/P&gt;&lt;P&gt;I took your advice and it was what i needed, thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Worked perfect..&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Fred&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Dec 2014 18:35:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/DateTime-group-by/m-p/138360#M37132</guid>
      <dc:creator>fred_major</dc:creator>
      <dc:date>2014-12-05T18:35:22Z</dc:date>
    </item>
  </channel>
</rss>

