<?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: Using Proc SQL - Date Function in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Using-Proc-SQL-Date-Function/m-p/75683#M21966</link>
    <description>You will need to use a SAS PROC SQL compatible approach - one suggestion would be to use a SAS DATE (numeric) variable and combine it with an output format DOWNAME in your SELECT.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search argument, this topic/post:&lt;BR /&gt;
&lt;BR /&gt;
proc sql select formatted value site:sas.com</description>
    <pubDate>Mon, 19 Apr 2010 22:48:49 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2010-04-19T22:48:49Z</dc:date>
    <item>
      <title>Using Proc SQL - Date Function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-Proc-SQL-Date-Function/m-p/75682#M21965</link>
      <description>Hi, &lt;BR /&gt;
&lt;BR /&gt;
 I have column in my dataset which contains date in the following format YYYYMMDD (20100419). Now using Proc SQL I want to know which day of the week and Day it is (For ex: Day of week : 1 &amp;amp;&amp;amp; Day = Monday). &lt;BR /&gt;
&lt;BR /&gt;
I am trying to use DATENAME in-built funtion available in SQL but it gives me error stating "Datename function could not be located". &lt;BR /&gt;
&lt;BR /&gt;
My Query: &lt;BR /&gt;
Proc SQL;&lt;BR /&gt;
Select Datename(Weekday, Col_Name);&lt;BR /&gt;
Quit;&lt;BR /&gt;
&lt;BR /&gt;
Please help me out with this issue. &lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance. &lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Pritish</description>
      <pubDate>Mon, 19 Apr 2010 20:15:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-Proc-SQL-Date-Function/m-p/75682#M21965</guid>
      <dc:creator>Pritish</dc:creator>
      <dc:date>2010-04-19T20:15:53Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc SQL - Date Function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-Proc-SQL-Date-Function/m-p/75683#M21966</link>
      <description>You will need to use a SAS PROC SQL compatible approach - one suggestion would be to use a SAS DATE (numeric) variable and combine it with an output format DOWNAME in your SELECT.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Suggested Google advanced search argument, this topic/post:&lt;BR /&gt;
&lt;BR /&gt;
proc sql select formatted value site:sas.com</description>
      <pubDate>Mon, 19 Apr 2010 22:48:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-Proc-SQL-Date-Function/m-p/75683#M21966</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2010-04-19T22:48:49Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc SQL - Date Function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-Proc-SQL-Date-Function/m-p/75684#M21967</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
There are SQL flavours and not all functions are available in all implementations.&lt;BR /&gt;
&lt;BR /&gt;
For SAS SQL:&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
  Col_Name='20100419';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Proc SQL;&lt;BR /&gt;
  Select put(input(Col_Name,yymmdd8.),weekdate.)&lt;BR /&gt;
    from have;&lt;BR /&gt;
Quit;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
You have first to translate the (date) text string into a numeric SAS date (input) and then you can apply a format (put) on the result of how you want this SAS date printed.&lt;BR /&gt;
&lt;BR /&gt;
You'll find more formats here:&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/allprodslang/62304/HTML/default/syntaxByCategory-format.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/allprodslang/62304/HTML/default/syntaxByCategory-format.htm&lt;/A&gt;&lt;BR /&gt;
&lt;BR /&gt;
And if none of these formats suits your need then you can also construct your own as a picture format (PROC FORMAT).&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Tue, 20 Apr 2010 03:09:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-Proc-SQL-Date-Function/m-p/75684#M21967</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-04-20T03:09:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc SQL - Date Function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-Proc-SQL-Date-Function/m-p/561992#M74919</link>
      <description>&lt;P&gt;I have a same issue to convert a numeric(8) to date as YYYY-MM-DDl.&lt;/P&gt;&lt;P&gt;my table has a column, load_dt_id numeric (8)&amp;nbsp;&lt;/P&gt;&lt;P&gt;and in the table load_dt_id is 20161103&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;when I run procsql:&lt;/P&gt;&lt;P&gt;select input(put(load_dt_id, 10.),YYYYMM10.) as LOAD_DT from table_name;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and my result is still the same as 20161103 instead of 2016-11-03.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;how do I convert it from numeric to date, YYYY-MM-DD or to date with time?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Bach-Nga&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 15:02:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-Proc-SQL-Date-Function/m-p/561992#M74919</guid>
      <dc:creator>pepevo</dc:creator>
      <dc:date>2019-05-28T15:02:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc SQL - Date Function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-Proc-SQL-Date-Function/m-p/561995#M74920</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/270904"&gt;@pepevo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a same issue to convert a numeric(8) to date as YYYY-MM-DDl.&lt;/P&gt;
&lt;P&gt;my table has a column, load_dt_id numeric (8)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and in the table load_dt_id is 20161103&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;when I run procsql:&lt;/P&gt;
&lt;P&gt;select input(put(load_dt_id, 10.),YYYYMM10.) as LOAD_DT from table_name;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and my result is still the same as 20161103 instead of 2016-11-03.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how do I convert it from numeric to date, YYYY-MM-DD or to date with time?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bach-Nga&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you want to store hyphens in the value the you will need to create a character variable.&lt;/P&gt;
&lt;P&gt;If you want your DATE values to display in that style the use the YYMMDDD10. format. The third D is for DASH. You can leave off the third D as the default for the YYMMDD format is to use a dash when the width is long enough to have room for it.&lt;/P&gt;
&lt;P&gt;Note that there is no YYYYMM informat. There is a YYMMDD informat and a YYMM informat (which will set the date value to the first of the month).&lt;/P&gt;
&lt;P&gt;So if you have numeric values in YY,YYM,MDD format then you can convert them to DATE values and attach a format to have them displayed as YYYY-MM-DD values using syntax like this in SQL.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; input(put(load_dt_id, 8.),YYMMDD8.) as LOAD_DT format=yymmdd10.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to include a time component then you need to use DATETIME variable instead of DATE variable. Dates are stored as number of days. DATETIME is stored as number of seconds.&amp;nbsp; You can use DATEPART() and TIMEPART() to extract date and time values from datetime values.&amp;nbsp; You can use DHMS() function to construct datetime values from the components (D=Days, H=Hours, M=Minutes, S=Seconds).&amp;nbsp; So if you have DATE and a TIME value you can construct a DATETIME value using:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dhms(date,0,0,time)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 15:13:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-Proc-SQL-Date-Function/m-p/561995#M74920</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-28T15:13:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using Proc SQL - Date Function</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-Proc-SQL-Date-Function/m-p/561997#M74921</link>
      <description>&lt;P&gt;I did try that but didn't put "dd" in it.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;select input(put(load_dt_id, 10.),YYYYMM10.) as LOAD_DT format=yymm10. from table_name;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you for correcting my syntax so much.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;v/r,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Bach_Nga&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 15:16:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-Proc-SQL-Date-Function/m-p/561997#M74921</guid>
      <dc:creator>pepevo</dc:creator>
      <dc:date>2019-05-28T15:16:07Z</dc:date>
    </item>
  </channel>
</rss>

