<?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: Function Datepart in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72100#M20871</link>
    <description>Hi Reeza&lt;BR /&gt;
&lt;BR /&gt;
If needed how can i convert it back to character so that i can say get the mean?&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
CREATE TABLE MEAN_Calls AS&lt;BR /&gt;
SELECT date, MEAN(calls_handled)aS BPSMEAN&lt;BR /&gt;
FROM mean1&lt;BR /&gt;
group by date;&lt;BR /&gt;
QUIT;&lt;BR /&gt;
&lt;BR /&gt;
Above does not work, i'm assuming it is because the date is a number.&lt;BR /&gt;
&lt;BR /&gt;
Fred

This worked&lt;BR /&gt;
&lt;BR /&gt;
proc MEANS NOPRINT data=mean1;&lt;BR /&gt;
class date;&lt;BR /&gt;
var calls_handled;&lt;BR /&gt;
output out=new2  mean=calls_handled;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: fredbell</description>
    <pubDate>Thu, 21 Oct 2010 18:06:29 GMT</pubDate>
    <dc:creator>fredbell</dc:creator>
    <dc:date>2010-10-21T18:06:29Z</dc:date>
    <item>
      <title>Function Datepart</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72085#M20856</link>
      <description>Hello&lt;BR /&gt;
&lt;BR /&gt;
I am attempting to use Datepart function but in the log i end up with the error:&lt;BR /&gt;
&lt;BR /&gt;
Error: Function Datepart requires a numeric expression as argument 1&lt;BR /&gt;
&lt;BR /&gt;
Any suggestions?&lt;BR /&gt;
&lt;BR /&gt;
Fred</description>
      <pubDate>Tue, 14 Sep 2010 17:36:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72085#M20856</guid>
      <dc:creator>fredbell</dc:creator>
      <dc:date>2010-09-14T17:36:44Z</dc:date>
    </item>
    <item>
      <title>Re: Function Datepart</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72086#M20857</link>
      <description>Are you using it on a SAS datetime variable?  The function will not work given a character variable unless the variable is wrapped in an input statement converting it first to a SAS datetime variable.&lt;BR /&gt;
&lt;BR /&gt;
Art</description>
      <pubDate>Tue, 14 Sep 2010 18:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72086#M20857</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2010-09-14T18:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: Function Datepart</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72087#M20858</link>
      <description>It would help if you give us an example.&lt;BR /&gt;
&lt;BR /&gt;
All I can tell you is that you are trying to use DATEPART on a character variable, and that causes an error.</description>
      <pubDate>Tue, 14 Sep 2010 18:12:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72087#M20858</guid>
      <dc:creator>Paige</dc:creator>
      <dc:date>2010-09-14T18:12:46Z</dc:date>
    </item>
    <item>
      <title>Re: Function Datepart</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72088#M20859</link>
      <description>Hello&lt;BR /&gt;
&lt;BR /&gt;
Trouble with Datepart, any suggestions.&lt;BR /&gt;
&lt;BR /&gt;
I'm told if i wrap variable in an input statement it will convert it to sas datetime, can anyone provide example?&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
create table Total_CallsHandled_by_Day as&lt;BR /&gt;
select datepart(ReportTime), sum(agentcallshandled) as Calls_Handled&lt;BR /&gt;
from ccar_callshandled;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
Log below&lt;BR /&gt;
&lt;BR /&gt;
251  proc sql;&lt;BR /&gt;
252  create table Total_CallsHandled_by_Day as&lt;BR /&gt;
253  select datepart(ReportTime), sum(agentcallshandled) as Calls_Handled&lt;BR /&gt;
254  from ccar_callshandled;&lt;BR /&gt;
ERROR: Function DATEPART requires a numeric expression as argument 1.&lt;BR /&gt;
255  quit;&lt;BR /&gt;
NOTE: The SAS System stopped processing this step because of errors.&lt;BR /&gt;
NOTE: PROCEDURE SQL used (Total process time):&lt;BR /&gt;
      real time           0.00 seconds&lt;BR /&gt;
      cpu time            0.00 seconds&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
ReportTime example 2010-09-30 00:00:00.000000&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Please help

Message was edited by: fredbell</description>
      <pubDate>Thu, 14 Oct 2010 17:09:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72088#M20859</guid>
      <dc:creator>fredbell</dc:creator>
      <dc:date>2010-10-14T17:09:03Z</dc:date>
    </item>
    <item>
      <title>Re: Function Datepart</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72089#M20860</link>
      <description>I don't understand why it was necessary to abandon this thread:&lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?threadID=11462&amp;amp;tstart=0" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?threadID=11462&amp;amp;tstart=0&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
which has specific information - you are referencing a CHARACTER type variable ReportTime which you must first convert to a NUMERIC (SAS DATETIME type) variable using the INPUT(&lt;VARIABLE&gt;,&lt;INFORMAT&gt;)  function in your SELECT statement.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;/INFORMAT&gt;&lt;/VARIABLE&gt;</description>
      <pubDate>Thu, 14 Oct 2010 17:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72089#M20860</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-10-14T17:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: Function Datepart</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72090#M20861</link>
      <description>Hi Scott&lt;BR /&gt;
&lt;BR /&gt;
I did not abandoned, my last post on that thread mentioned i was successful with that issue and gave example of what i did.&lt;BR /&gt;
&lt;BR /&gt;
Scott i always appreciate help but sometimes for a newbie it is difficult without an example.&lt;BR /&gt;
&lt;BR /&gt;
Were in the select statement should this be put, also what &amp;gt;,&lt;INFORMAT&gt; should i use?&lt;BR /&gt;
&lt;BR /&gt;
Fred&lt;/INFORMAT&gt;</description>
      <pubDate>Thu, 14 Oct 2010 18:17:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72090#M20861</guid>
      <dc:creator>fredbell</dc:creator>
      <dc:date>2010-10-14T18:17:58Z</dc:date>
    </item>
    <item>
      <title>Re: Function Datepart</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72091#M20862</link>
      <description>As someone had mentioned in the last thread your reporttime variable is stored as a character rather than a date. &lt;BR /&gt;
&lt;BR /&gt;
If you create a new variable with the proper format then you will no longer have this issues. Basically, if you don't fix this issue, you'll have a lot of issues working with the variable trying to calculate durations, or comparing to other dates or formatting to other date time formats...I could go on.  &lt;BR /&gt;
&lt;BR /&gt;
Its bad programming, fix it in the initial data creation/import step if possible. &lt;BR /&gt;
&lt;BR /&gt;
data example;&lt;BR /&gt;
	wrong='2010-09-30 00:00:00.000000'; *this is what you have;&lt;BR /&gt;
	correct=input(wrong, anydtdtm22.); *this converts it to datetime variable;&lt;BR /&gt;
	format correct datetime18.;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Hope that helps to clarify the issues.</description>
      <pubDate>Thu, 14 Oct 2010 18:47:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72091#M20862</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2010-10-14T18:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: Function Datepart</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72092#M20863</link>
      <description>Hi Reeza&lt;BR /&gt;
&lt;BR /&gt;
This is what i did&lt;BR /&gt;
&lt;BR /&gt;
data example;&lt;BR /&gt;
set ccar_callshandled;&lt;BR /&gt;
correct=input(ReportTime, anydtdtm22.); *this converts it to datetime variable;&lt;BR /&gt;
format correct datetime9.;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Old ReportTime 2010-10-10 00:00:00.000000&lt;BR /&gt;
New ReportTime labled correct in dateset 10OCT2010&lt;BR /&gt;
&lt;BR /&gt;
Thanks&lt;BR /&gt;
&lt;BR /&gt;
Fred</description>
      <pubDate>Thu, 14 Oct 2010 19:00:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72092#M20863</guid>
      <dc:creator>fredbell</dc:creator>
      <dc:date>2010-10-14T19:00:33Z</dc:date>
    </item>
    <item>
      <title>Re: Function Datepart</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72093#M20864</link>
      <description>Given all the information and feedback, you chose to treat the "symptom" rather than solving the problem (by changing your literal string -- hoping that a left-to-right byte comparison will still work), which in-turn created another challenge in your variable SELECT -- that is my point.  Had you addressed the "character string date-time" problem and converted the variable on input to a SAS numeric-type DATETIME variable, then you would not have needed to register this post.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry</description>
      <pubDate>Thu, 14 Oct 2010 20:43:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72093#M20864</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-10-14T20:43:26Z</dc:date>
    </item>
    <item>
      <title>Re: Function Datepart</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72094#M20865</link>
      <description>Scott i am just doing the best i can, I searched google advance and web forum as you suggested without coming up with an example i could understand.&lt;BR /&gt;
I asked several times if you could provide an example but you just kept telling me the same thing.&lt;BR /&gt;
&lt;BR /&gt;
I would like to do things correctly, that of course is what i want.&lt;BR /&gt;
&lt;BR /&gt;
Fred&lt;BR /&gt;
&lt;BR /&gt;
What does register post mean?&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: fredbell

Reeza has provided an example that seems to do what you are mentioning, correct?&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: fredbell</description>
      <pubDate>Thu, 14 Oct 2010 23:08:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72094#M20865</guid>
      <dc:creator>fredbell</dc:creator>
      <dc:date>2010-10-14T23:08:57Z</dc:date>
    </item>
    <item>
      <title>Re: Function Datepart</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72095#M20866</link>
      <description>Hi Reeza&lt;BR /&gt;
&lt;BR /&gt;
How would I convert this to date instead of datetime?&lt;BR /&gt;
&lt;BR /&gt;
Fred</description>
      <pubDate>Fri, 15 Oct 2010 17:05:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72095#M20866</guid>
      <dc:creator>fredbell</dc:creator>
      <dc:date>2010-10-15T17:05:23Z</dc:date>
    </item>
    <item>
      <title>Re: Function Datepart</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72096#M20867</link>
      <description>&amp;gt; How would I convert this to date instead of&lt;BR /&gt;
&amp;gt; datetime?&lt;BR /&gt;
&lt;BR /&gt;
Did you try the function Datepart?</description>
      <pubDate>Fri, 15 Oct 2010 17:13:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72096#M20867</guid>
      <dc:creator>RickM</dc:creator>
      <dc:date>2010-10-15T17:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: Function Datepart</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72097#M20868</link>
      <description>Thanks Rick, that worked.&lt;BR /&gt;
&lt;BR /&gt;
This thing is driving me crazy.&lt;BR /&gt;
&lt;BR /&gt;
Fred</description>
      <pubDate>Fri, 15 Oct 2010 17:25:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72097#M20868</guid>
      <dc:creator>fredbell</dc:creator>
      <dc:date>2010-10-15T17:25:33Z</dc:date>
    </item>
    <item>
      <title>Re: Function Datepart</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72098#M20869</link>
      <description>You really need to get a clear understanding about your external data representation, specifically that you are working with a character-string of data that appears as a date-time.  And within SAS, you must convert that string to a SAS numeric DATETIME (or DATE) variable value, so that SAS functions can operate on the resulting numeric value (represented as either a datetime value ( "seconds since 1/1/1960") or a date value ("days since 1/1/1960").&lt;BR /&gt;
&lt;BR /&gt;
The SAS Language Dictionary and SAS Language Concepts guides each have reference material on this topic, and also the SAS support website has technical / conference papers on the topic.&lt;BR /&gt;
&lt;BR /&gt;
Until you devote time to self-initiated review and attention, these facilities will continue to course you have suggested.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 15 Oct 2010 18:48:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72098#M20869</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-10-15T18:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: Function Datepart</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72099#M20870</link>
      <description>See this page when you get a chance, for help on working with data in SAS. &lt;BR /&gt;
&lt;BR /&gt;
&lt;A href="http://www.ats.ucla.edu/stat/sas/modules/default.htm" target="_blank"&gt;http://www.ats.ucla.edu/stat/sas/modules/default.htm&lt;/A&gt;</description>
      <pubDate>Fri, 15 Oct 2010 22:08:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72099#M20870</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2010-10-15T22:08:24Z</dc:date>
    </item>
    <item>
      <title>Re: Function Datepart</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72100#M20871</link>
      <description>Hi Reeza&lt;BR /&gt;
&lt;BR /&gt;
If needed how can i convert it back to character so that i can say get the mean?&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
CREATE TABLE MEAN_Calls AS&lt;BR /&gt;
SELECT date, MEAN(calls_handled)aS BPSMEAN&lt;BR /&gt;
FROM mean1&lt;BR /&gt;
group by date;&lt;BR /&gt;
QUIT;&lt;BR /&gt;
&lt;BR /&gt;
Above does not work, i'm assuming it is because the date is a number.&lt;BR /&gt;
&lt;BR /&gt;
Fred

This worked&lt;BR /&gt;
&lt;BR /&gt;
proc MEANS NOPRINT data=mean1;&lt;BR /&gt;
class date;&lt;BR /&gt;
var calls_handled;&lt;BR /&gt;
output out=new2  mean=calls_handled;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: fredbell</description>
      <pubDate>Thu, 21 Oct 2010 18:06:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72100#M20871</guid>
      <dc:creator>fredbell</dc:creator>
      <dc:date>2010-10-21T18:06:29Z</dc:date>
    </item>
    <item>
      <title>Re: Function Datepart</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72101#M20872</link>
      <description>that should work.  I need the log error to help debug. One suggestion would be to separate the as from the ) and possibly get the date as a 'date' rather than datetime (which is what i think you had it before).&lt;BR /&gt;
&lt;BR /&gt;
PROC SQL;&lt;BR /&gt;
CREATE TABLE MEAN_Calls AS&lt;BR /&gt;
SELECT datepart(date) as grouped_date, avg(calls_handled) AS BPSMEAN&lt;BR /&gt;
FROM mean1&lt;BR /&gt;
group by datepart(date);&lt;BR /&gt;
QUIT;

Message was edited by: Reeza</description>
      <pubDate>Thu, 21 Oct 2010 18:55:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Function-Datepart/m-p/72101#M20872</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2010-10-21T18:55:53Z</dc:date>
    </item>
  </channel>
</rss>

