<?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 to convert char date to date in SQL SAS in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356312#M83548</link>
    <description>&lt;P&gt;Edit, in your given scenario you can only use date9 style dates as '....'d values. &amp;nbsp;Use input():&lt;/P&gt;
&lt;PRE&gt;proc sql;
select date format mmddyy10. from ab where date &amp;lt; input('03/20/1967',mmddyy10.);
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Doesn't make any sense. &amp;nbsp;What does not being able to change the dataset have todo with using SQL? &amp;nbsp;Why can't you make new datasets? &amp;nbsp;Anyway, as I said, you use dates in SQL exactly the same as in datastep, you use input() or put() to change datatypes:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  ...
  where input(chardate,mmddyy10.) &amp;lt;= otherdatevar
...
quit;&lt;/PRE&gt;
&lt;P&gt;If you don't provide the required information for us to know what you are doing the answer will be general.&lt;/P&gt;</description>
    <pubDate>Fri, 05 May 2017 11:00:50 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-05-05T11:00:50Z</dc:date>
    <item>
      <title>How to convert char date to date in SQL SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356293#M83535</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please let me know that how I can convert Character Date value and use in where claus of proc sql.&lt;/P&gt;&lt;P&gt;For example :&lt;/P&gt;&lt;P&gt;I have data like:&lt;/P&gt;&lt;PRE&gt;data ab;
input date1;
cards;
05/21/1963
03/20/1967
07/23/1961
08/03/1975
01/24/1960
;
run;&lt;/PRE&gt;&lt;P&gt;Above is only an example case. So Now i want to fetch all those rows having date greater than 2 Feb 1963.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So right now i am unable to first convert this date1 to date using proc sql then, i beleive after that we can use gt in where clause of sql syntax.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 10:32:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356293#M83535</guid>
      <dc:creator>tjain90</dc:creator>
      <dc:date>2017-05-05T10:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert char date to date in SQL SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356295#M83537</link>
      <description>&lt;P&gt;You say that your problem is to convert character date values, but in the given data, you have defined your date variables as numeric?&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 10:39:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356295#M83537</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-05-05T10:39:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert char date to date in SQL SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356296#M83538</link>
      <description>&lt;P&gt;Its the same as reading or using dates in any other part of SAS:&lt;/P&gt;
&lt;PRE&gt;data ab;
  informat date1 mmddyy10.;
  input date1;
  format date1 date9.;
cards;
05/21/1963
03/20/1967
07/23/1961
08/03/1975
01/24/1960
;
run;
data have;
  chk='01jan1990'd;
run;

proc sql;
  create table WANT as
  select *
  from   AB A
  left join HAVE B
  on    1=1
  where  B.CHK &amp;gt; A.DATE1;
quit;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 May 2017 10:41:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356296#M83538</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-05T10:41:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert char date to date in SQL SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356299#M83541</link>
      <description>Hi draycut, it was an typo. Please assume it as date1$10.&lt;BR /&gt;&lt;BR /&gt;##- Please type your reply above this line. Simple formatting, no&lt;BR /&gt;attachments. -##</description>
      <pubDate>Fri, 05 May 2017 10:45:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356299#M83541</guid>
      <dc:creator>tjain90</dc:creator>
      <dc:date>2017-05-05T10:45:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert char date to date in SQL SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356302#M83544</link>
      <description>&lt;P&gt;Thanks RW9.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the scenerio is i cannot change this original data set. So i am bounded to use proc sql. So is there any way to convert this using sql only. I accept it would not good approach but scenerio is forcing to use proc sql&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 10:48:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356302#M83544</guid>
      <dc:creator>tjain90</dc:creator>
      <dc:date>2017-05-05T10:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert char date to date in SQL SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356309#M83547</link>
      <description>&lt;P&gt;Also RW9, Can you please check what wrong I am doing in this code ?&lt;/P&gt;&lt;P&gt;Why below error occurs:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ERROR: Invalid date/time/datetime constant '03/20/1967'd.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ab;
input date mmddyy10.;
cards;
05/21/1963
03/20/1967
07/23/1961
08/03/1975
01/24/1960
;
run;

proc sql;
select date format mmddyy10. from ab where date&amp;lt;'03/20/1967'd;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 May 2017 10:56:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356309#M83547</guid>
      <dc:creator>tjain90</dc:creator>
      <dc:date>2017-05-05T10:56:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert char date to date in SQL SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356312#M83548</link>
      <description>&lt;P&gt;Edit, in your given scenario you can only use date9 style dates as '....'d values. &amp;nbsp;Use input():&lt;/P&gt;
&lt;PRE&gt;proc sql;
select date format mmddyy10. from ab where date &amp;lt; input('03/20/1967',mmddyy10.);
quit;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Doesn't make any sense. &amp;nbsp;What does not being able to change the dataset have todo with using SQL? &amp;nbsp;Why can't you make new datasets? &amp;nbsp;Anyway, as I said, you use dates in SQL exactly the same as in datastep, you use input() or put() to change datatypes:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  ...
  where input(chardate,mmddyy10.) &amp;lt;= otherdatevar
...
quit;&lt;/PRE&gt;
&lt;P&gt;If you don't provide the required information for us to know what you are doing the answer will be general.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 11:00:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356312#M83548</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-05T11:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert char date to date in SQL SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356313#M83549</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/131624"&gt;@tjain90&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Also RW9, Can you please check what wrong I am doing in this code ?&lt;/P&gt;
&lt;P&gt;Why below error occurs:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;ERROR: Invalid date/time/datetime constant '03/20/1967'd.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ab;
input date mmddyy10.;
cards;
05/21/1963
03/20/1967
07/23/1961
08/03/1975
01/24/1960
;
run;

proc sql;
select date format mmddyy10. from ab where date&amp;lt;'03/20/1967'd;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You should start to heed my Maxim #1 and read the documentation. The proper way to write your SAS date literal is '20mar1967'd.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 11:00:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356313#M83549</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-05T11:00:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert char date to date in SQL SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356315#M83551</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/131624"&gt;@tjain90&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks RW9.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But the scenerio is i cannot change this original data set. So i am bounded to use proc sql. So is there any way to convert this using sql only. I accept it would not good approach but scenerio is forcing to use proc sql&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That does not prohibit recreating the data set with a DATA step &lt;U&gt;or&lt;/U&gt; SQL in WORK. So you are NOT forced to use SQL only.&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 11:02:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356315#M83551</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-05T11:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert char date to date in SQL SAS</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356330#M83555</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ab;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;length&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; date1 $&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; date1 $;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;cards&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;05/21/1963&lt;/P&gt;
&lt;P&gt;03/20/1967&lt;/P&gt;
&lt;P&gt;07/23/1961&lt;/P&gt;
&lt;P&gt;08/03/1975&lt;/P&gt;
&lt;P&gt;01/24/1960&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; cd;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;format&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; date2 &lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;date9.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ab;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;date2=input(date1,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;mmddyy10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;sql&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;create&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;table&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; date1,input(date1,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;mmddyy10.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; date2 format=&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;mmddyy8.&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;ab;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;quit&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 May 2017 11:38:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-convert-char-date-to-date-in-SQL-SAS/m-p/356330#M83555</guid>
      <dc:creator>rawindar</dc:creator>
      <dc:date>2017-05-05T11:38:50Z</dc:date>
    </item>
  </channel>
</rss>

