<?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: string to sas date in Developers</title>
    <link>https://communities.sas.com/t5/Developers/string-to-sas-date/m-p/4128#M1898</link>
    <description>Hi,&lt;BR /&gt;
  Refer to my July 20 post in this forum prior posting:&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=6918ᬆ" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=6918ᬆ&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
Your easiest solution (in my opinion) is to use a SAS date constant in your where clause. The form that a date constant has to take is:&lt;BR /&gt;
[pre]&lt;BR /&gt;
"ddmmmyyyy"d or "ddmmyy"d&lt;BR /&gt;
[/pre]&lt;BR /&gt;
   &lt;BR /&gt;
That means the best solution would be to set your parameter to the DATE9 form of the date and then you don't have to worry about conversion.&lt;BR /&gt;
[pre]&lt;BR /&gt;
&lt;BR /&gt;
data btime;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input name $ bdtime : datetime.;&lt;BR /&gt;
  bdtime2 = bdtime;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
anna 15Nov1950:07:15:00&lt;BR /&gt;
barb 15Nov1950:10:45:32&lt;BR /&gt;
cali 15Nov1950:06:33:27&lt;BR /&gt;
dora 15Nov1950:03:25:59&lt;BR /&gt;
yora 15Nov1960:04:04:07&lt;BR /&gt;
zora 15Nov1984:11:56:32&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
   &lt;BR /&gt;
proc print date=btime;&lt;BR /&gt;
title 'How to get ONLY the people born after November 15, 1950';&lt;BR /&gt;
where datepart(bdtime) gt "15Nov1950"d;&lt;BR /&gt;
format bdtime2 datetime20.;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
If your &amp;amp;BEGIN_DATE was already in the form 15Nov1950, then you could just code the above WHERE clause as:&lt;BR /&gt;
[pre]&lt;BR /&gt;
where datepart(bdtime) gt "&amp;amp;BEGIN_DATE"d;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
  &lt;BR /&gt;
BUT, if your users need/want to select a different date format, then you'll need to convert YOUR macro parm "&amp;amp;BEGIN_DATE from one form into another date form. So your stored process will have to contain macro code to perform the conversion before the WHERE clause:&lt;BR /&gt;
  &lt;BR /&gt;
[pre]&lt;BR /&gt;
%let begin_date = 11/15/1950;  /* mimics what is coming from user */&lt;BR /&gt;
%let datenum = %sysfunc(inputn(&amp;amp;begin_date,anydtdte10.));&lt;BR /&gt;
%let wantdate = %sysfunc(putn(&amp;amp;datenum,date9.));&lt;BR /&gt;
   &lt;BR /&gt;
ods listing;&lt;BR /&gt;
proc print date=btime;&lt;BR /&gt;
title 'How to "fix" when date is not initially in right form for date constant';&lt;BR /&gt;
where datepart(bdtime) gt "&amp;amp;wantdate"d;&lt;BR /&gt;
format bdtime2 datetime20.;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
    <pubDate>Thu, 09 Aug 2007 16:55:31 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2007-08-09T16:55:31Z</dc:date>
    <item>
      <title>string to sas date</title>
      <link>https://communities.sas.com/t5/Developers/string-to-sas-date/m-p/4127#M1897</link>
      <description>In my data I have a hire_date field which contains datetime. I used datepart to get the numeric value of the date. Now the user will enter begin_date which is a string ex. is 01/01/2006.  I need to to convert the string to sas date so I want to select the records hire_date is greater than begin_date. I am having tough time to figure out&lt;BR /&gt;
Can any one help me.</description>
      <pubDate>Thu, 09 Aug 2007 14:42:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/string-to-sas-date/m-p/4127#M1897</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-08-09T14:42:18Z</dc:date>
    </item>
    <item>
      <title>Re: string to sas date</title>
      <link>https://communities.sas.com/t5/Developers/string-to-sas-date/m-p/4128#M1898</link>
      <description>Hi,&lt;BR /&gt;
  Refer to my July 20 post in this forum prior posting:&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/thread.jspa?messageID=6918ᬆ" target="_blank"&gt;http://support.sas.com/forums/thread.jspa?messageID=6918ᬆ&lt;/A&gt;&lt;BR /&gt;
 &lt;BR /&gt;
Your easiest solution (in my opinion) is to use a SAS date constant in your where clause. The form that a date constant has to take is:&lt;BR /&gt;
[pre]&lt;BR /&gt;
"ddmmmyyyy"d or "ddmmyy"d&lt;BR /&gt;
[/pre]&lt;BR /&gt;
   &lt;BR /&gt;
That means the best solution would be to set your parameter to the DATE9 form of the date and then you don't have to worry about conversion.&lt;BR /&gt;
[pre]&lt;BR /&gt;
&lt;BR /&gt;
data btime;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input name $ bdtime : datetime.;&lt;BR /&gt;
  bdtime2 = bdtime;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
anna 15Nov1950:07:15:00&lt;BR /&gt;
barb 15Nov1950:10:45:32&lt;BR /&gt;
cali 15Nov1950:06:33:27&lt;BR /&gt;
dora 15Nov1950:03:25:59&lt;BR /&gt;
yora 15Nov1960:04:04:07&lt;BR /&gt;
zora 15Nov1984:11:56:32&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
   &lt;BR /&gt;
proc print date=btime;&lt;BR /&gt;
title 'How to get ONLY the people born after November 15, 1950';&lt;BR /&gt;
where datepart(bdtime) gt "15Nov1950"d;&lt;BR /&gt;
format bdtime2 datetime20.;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
If your &amp;amp;BEGIN_DATE was already in the form 15Nov1950, then you could just code the above WHERE clause as:&lt;BR /&gt;
[pre]&lt;BR /&gt;
where datepart(bdtime) gt "&amp;amp;BEGIN_DATE"d;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
  &lt;BR /&gt;
BUT, if your users need/want to select a different date format, then you'll need to convert YOUR macro parm "&amp;amp;BEGIN_DATE from one form into another date form. So your stored process will have to contain macro code to perform the conversion before the WHERE clause:&lt;BR /&gt;
  &lt;BR /&gt;
[pre]&lt;BR /&gt;
%let begin_date = 11/15/1950;  /* mimics what is coming from user */&lt;BR /&gt;
%let datenum = %sysfunc(inputn(&amp;amp;begin_date,anydtdte10.));&lt;BR /&gt;
%let wantdate = %sysfunc(putn(&amp;amp;datenum,date9.));&lt;BR /&gt;
   &lt;BR /&gt;
ods listing;&lt;BR /&gt;
proc print date=btime;&lt;BR /&gt;
title 'How to "fix" when date is not initially in right form for date constant';&lt;BR /&gt;
where datepart(bdtime) gt "&amp;amp;wantdate"d;&lt;BR /&gt;
format bdtime2 datetime20.;&lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Thu, 09 Aug 2007 16:55:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/string-to-sas-date/m-p/4128#M1898</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-08-09T16:55:31Z</dc:date>
    </item>
    <item>
      <title>Re: string to sas date</title>
      <link>https://communities.sas.com/t5/Developers/string-to-sas-date/m-p/4129#M1899</link>
      <description>Hi Cynthia,  &lt;BR /&gt;
  I tried whatever u suggested, It worked. Thank you very much&lt;BR /&gt;
&lt;BR /&gt;
 Thanks lot</description>
      <pubDate>Thu, 09 Aug 2007 18:08:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Developers/string-to-sas-date/m-p/4129#M1899</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-08-09T18:08:55Z</dc:date>
    </item>
  </channel>
</rss>

