<?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: if statement in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/if-statement/m-p/100571#M28270</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Two problems&lt;/P&gt;&lt;P&gt;1)&amp;nbsp; The IF statement does not support that SQL specific BETWEEN operator even though the WHERE statement does.&lt;/P&gt;&lt;P&gt;Use the normal SAS syntax :&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-family: 'courier new', courier;"&gt;"&amp;amp;begin"d &amp;lt;= datepart(time) &amp;lt;= "&amp;amp;end"d&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Or the expanded syntax :&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-family: 'courier new', courier;"&gt;"&amp;amp;begin"d &amp;lt;= datepart(time) and &lt;SPAN style="font-family: 'courier new', courier;"&gt;datepart(time)&lt;/SPAN&gt; &amp;lt;= "&amp;amp;end"d&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2) You cannot compare a numeric (dates are numbers of days since 1/1/1960) with a character string. If you format the values in DATE format then you can use date literals.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let begin=01JAN2013;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let end=31MAR2013;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let begin2=01APR2013;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let end2=30JUN2013;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data want want2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if "&amp;amp;begin"d &amp;lt;= datepart(time) &amp;lt;= "&amp;amp;end"d then output want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if "&amp;amp;begin2"d &amp;lt;= datepart(time) &amp;lt;= "&amp;amp;end2"d then output want2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 05 Aug 2013 03:52:49 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2013-08-05T03:52:49Z</dc:date>
    <item>
      <title>if statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/if-statement/m-p/100570#M28269</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;HI Team,&lt;/P&gt;&lt;P&gt;i was trying to use an if condition like the following and I get a syntax error.&lt;/P&gt;&lt;P&gt;could you please help me correct this?????&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DAta want want2;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;If datepart(time) between "begin" and "end " then output want;&lt;/P&gt;&lt;P&gt;if datepart(time) between "begin2 " and "end2" theN output want2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;THanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Aug 2013 03:43:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/if-statement/m-p/100570#M28269</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2013-08-05T03:43:20Z</dc:date>
    </item>
    <item>
      <title>Re: if statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/if-statement/m-p/100571#M28270</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Two problems&lt;/P&gt;&lt;P&gt;1)&amp;nbsp; The IF statement does not support that SQL specific BETWEEN operator even though the WHERE statement does.&lt;/P&gt;&lt;P&gt;Use the normal SAS syntax :&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-family: 'courier new', courier;"&gt;"&amp;amp;begin"d &amp;lt;= datepart(time) &amp;lt;= "&amp;amp;end"d&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Or the expanded syntax :&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="font-family: 'courier new', courier;"&gt;"&amp;amp;begin"d &amp;lt;= datepart(time) and &lt;SPAN style="font-family: 'courier new', courier;"&gt;datepart(time)&lt;/SPAN&gt; &amp;lt;= "&amp;amp;end"d&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;2) You cannot compare a numeric (dates are numbers of days since 1/1/1960) with a character string. If you format the values in DATE format then you can use date literals.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let begin=01JAN2013;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let end=31MAR2013;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let begin2=01APR2013;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;%let end2=30JUN2013;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;data want want2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; set have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if "&amp;amp;begin"d &amp;lt;= datepart(time) &amp;lt;= "&amp;amp;end"d then output want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;&amp;nbsp; if "&amp;amp;begin2"d &amp;lt;= datepart(time) &amp;lt;= "&amp;amp;end2"d then output want2;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Aug 2013 03:52:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/if-statement/m-p/100571#M28270</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-08-05T03:52:49Z</dc:date>
    </item>
    <item>
      <title>Re: if statement</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/if-statement/m-p/100572#M28271</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you very much Tom. That was very helpful.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 05 Aug 2013 03:58:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/if-statement/m-p/100572#M28271</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2013-08-05T03:58:16Z</dc:date>
    </item>
  </channel>
</rss>

