<?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 a date in a case statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-a-date-in-a-case-statement/m-p/375344#M276458</link>
    <description>&lt;P&gt;I've got a table with a person reference and the first date they went on a holiday, I want to count how many times they have been on another holiday in the 365 days since their first holiday&lt;/P&gt;&lt;P&gt;So I've tried to bring back all the dates they have been on a holiday in the last 365 days with the following code:&lt;/P&gt;&lt;P&gt;Case&lt;BR /&gt;When t3.BOOKING_STATUS_GROUP_NAME="Firm" and t3.BREAK_TYPE in ("AD","FA") and Gross_Cost&amp;gt;1 and Gross_Cost&amp;lt;10000 and DATDIF( t1.MIN_of_ARRIVAL_DATE,t3.ARRIVAL_DATE, 'Actual') BETWEEN 1 AND 365&lt;BR /&gt;Then t3.ARRIVAL_DATE&lt;BR /&gt;Else 0&lt;BR /&gt;End&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you suggest a better way to do this?&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jul 2017 14:52:23 GMT</pubDate>
    <dc:creator>VanessaP</dc:creator>
    <dc:date>2017-07-12T14:52:23Z</dc:date>
    <item>
      <title>Using a date in a case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-date-in-a-case-statement/m-p/375323#M276455</link>
      <description>&lt;P&gt;I'm creating a case statement saying &amp;nbsp;"Case when X = Y then output a&amp;nbsp;date field else Null". &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When using null, 'm getting error messages saying that its not the same data type. &amp;nbsp;I've changed it to a dummy date (01Jan1970) and the error doesn't seem to recognise the date. &amp;nbsp;I'm getting a syntax error that seems to expect an operator.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 14:15:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-date-in-a-case-statement/m-p/375323#M276455</guid>
      <dc:creator>VanessaP</dc:creator>
      <dc:date>2017-07-12T14:15:41Z</dc:date>
    </item>
    <item>
      <title>Re: Using a date in a case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-date-in-a-case-statement/m-p/375324#M276456</link>
      <description>&lt;P&gt;Please show the code you are using and error messages from the log in a code box opened with the forum {i} menu icon.&lt;/P&gt;
&lt;P&gt;Also indicate if this is being run as pass through to an external database system.&lt;/P&gt;
&lt;P&gt;SAS does not actually understand "null". Missing values are indicated with a . for numeric or blank ("") for character variables. Likely you tried to assign character to numeric in some flavor.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 14:23:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-date-in-a-case-statement/m-p/375324#M276456</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-07-12T14:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: Using a date in a case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-date-in-a-case-statement/m-p/375339#M276457</link>
      <description>&lt;P&gt;HI:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; It is not clear where you're using your CASE expression. Is it in a PROC SQL? What is the exact code that you are trying and the log that shows the EXACT error message.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; What do you mean by "output a date field" -- are you trying to make a date variable and assign a value?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; What do you mean by "error doesn't recognize the date" -- did you try something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; newdate = 01Jan1970;&lt;/P&gt;
&lt;P&gt;or did you try something like this&lt;/P&gt;
&lt;P&gt;newdate = '01Jan1970'd;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Remember that a date variable is just a SAS numeric variable that is holding the number of days since Jan 1, 1960 like this:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/10279i4C3A2BC3200327D3/image-size/original?v=1.0&amp;amp;px=-1" alt="dates_offset_from_0.png" title="dates_offset_from_0.png" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; So Dec 27, 1959 would be internally stored as -5 and Jan 9, 1960 would be internally stored as 9. But you don't want to have to figure out what the number is for July 4, 2017, so if you did something like this:&lt;/P&gt;
&lt;P&gt;what_is_this_date = '04Jul2017'd;&lt;/P&gt;
&lt;P&gt;then SAS would take the date constant in the expression and show you a value of 21004 as shown below:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/10280i5AC5B9B30AC35A4E/image-size/original?v=1.0&amp;amp;px=-1" alt="what_is_date.png" title="what_is_date.png" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Without seeing the code you tried or the error message you got, it's hard to provide a constructive answer. Here's an example that illustrates making a date variable (BIRTHDAY) in either a DATA step or PROC SQL for only certain values of the NAME variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cynthia&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/10281i70EC0FA94CB0BF4B/image-size/original?v=1.0&amp;amp;px=-1" alt="if_case.png" title="if_case.png" border="0" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 14:45:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-date-in-a-case-statement/m-p/375339#M276457</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2017-07-12T14:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: Using a date in a case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-date-in-a-case-statement/m-p/375344#M276458</link>
      <description>&lt;P&gt;I've got a table with a person reference and the first date they went on a holiday, I want to count how many times they have been on another holiday in the 365 days since their first holiday&lt;/P&gt;&lt;P&gt;So I've tried to bring back all the dates they have been on a holiday in the last 365 days with the following code:&lt;/P&gt;&lt;P&gt;Case&lt;BR /&gt;When t3.BOOKING_STATUS_GROUP_NAME="Firm" and t3.BREAK_TYPE in ("AD","FA") and Gross_Cost&amp;gt;1 and Gross_Cost&amp;lt;10000 and DATDIF( t1.MIN_of_ARRIVAL_DATE,t3.ARRIVAL_DATE, 'Actual') BETWEEN 1 AND 365&lt;BR /&gt;Then t3.ARRIVAL_DATE&lt;BR /&gt;Else 0&lt;BR /&gt;End&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you suggest a better way to do this?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 14:52:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-date-in-a-case-statement/m-p/375344#M276458</guid>
      <dc:creator>VanessaP</dc:creator>
      <dc:date>2017-07-12T14:52:23Z</dc:date>
    </item>
    <item>
      <title>Re: Using a date in a case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-date-in-a-case-statement/m-p/375350#M276459</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/85114"&gt;@VanessaP&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I've got a table with a person reference and the first date they went on a holiday, I want to count how many times they have been on another holiday in the 365 days since their first holiday&lt;/P&gt;
&lt;P&gt;So I've tried to bring back all the dates they have been on a holiday in the last 365 days with the following code:&lt;/P&gt;
&lt;P&gt;Case&lt;BR /&gt;When t3.BOOKING_STATUS_GROUP_NAME="Firm" and t3.BREAK_TYPE in ("AD","FA") and Gross_Cost&amp;gt;1 and Gross_Cost&amp;lt;10000 and DATDIF( t1.MIN_of_ARRIVAL_DATE,t3.ARRIVAL_DATE, 'Actual') BETWEEN 1 AND 365&lt;BR /&gt;Then t3.ARRIVAL_DATE&lt;BR /&gt;Else 0&lt;BR /&gt;End&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you suggest a better way to do this?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Post sample data. It looks like the logic is more complex than just a straight 'went on vacation in previous year' as well.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 15:04:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-date-in-a-case-statement/m-p/375350#M276459</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-12T15:04:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using a date in a case statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-a-date-in-a-case-statement/m-p/375366#M276460</link>
      <description>I don't have SAS at my fingertips but a suspect that NULL is an operator you can do logic with, but is not a constant that can be assigned. &lt;BR /&gt;So if you want to assign a NULL (or MISSING) use period &amp;lt;.&amp;gt; in the else clause given that you are using a numerical SAS date as your target column.</description>
      <pubDate>Wed, 12 Jul 2017 15:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-a-date-in-a-case-statement/m-p/375366#M276460</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-07-12T15:20:00Z</dc:date>
    </item>
  </channel>
</rss>

