<?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: Case when statement is not showing the correct output in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Case-when-statement-is-not-showing-the-correct-output/m-p/887507#M39385</link>
    <description>&lt;P&gt;INTCK() is counting interval boundaries between the start value and the target value.&amp;nbsp; When the START&amp;nbsp; value is AFTER the TARGET value then the answer is negative.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looks like you gave INTCK() a datetime value (number of seconds) for the start value and a date value (number of says) as the target value.&amp;nbsp; That is always going to be negative since treating a count of seconds as a count of days is going to result in some date that is way way way in the future since there are 24*60*60 seconds in a day.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Aug 2023 15:07:56 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2023-08-02T15:07:56Z</dc:date>
    <item>
      <title>Case when statement is not showing the correct output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Case-when-statement-is-not-showing-the-correct-output/m-p/887495#M39382</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I am running a code and used intck to find the dates which are more than 6 months and which are less than 6 months using case when statement. My code runs fine but in the output it shows all data as less than six months even if it is there for more than six months. Can you please suggest the mistake in the code? Thanks&lt;/P&gt;
&lt;P&gt;I want the output data to show accounts with more than 6 months from&amp;nbsp;EntryDate&amp;nbsp; and which are less than 6 months from&amp;nbsp;EntryDate.&lt;/P&gt;
&lt;P&gt;Sample dataset&lt;/P&gt;
&lt;P&gt;Data Status; &lt;BR /&gt;infile cards expandtabs; &lt;BR /&gt;input rep_group $ Serial client_code $ EntryDate :date9. Entrydatestatus$;&lt;BR /&gt;datalines ; &lt;BR /&gt;742 441844248 SHT1064 28JUL2023:00:00:00.000 Lessthansixmonths&lt;BR /&gt;100 442507166 PAY023 01AUG2022:00:00:00.000 Lessthansixmonths&lt;BR /&gt;125 442552022 PAY023 01AUG2023:00:00:00.000 Lessthansixmonths&lt;BR /&gt;100 442034021 EE07 28JUL2022:00:00:00.000 Lessthansixmonths&lt;BR /&gt;521 443717608 KLAA004 01AUG2023:00:00:00.000 Lessthansixmonths&lt;BR /&gt;; &lt;BR /&gt;run;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Status AS
Select rep_group,
Serial,
client_code,
EntryDate,
case when intck('month', EntryDate, date()) &amp;gt;= 6 then '6 or more months'
when intck('month', EntryDate, date()) &amp;lt; 6 then 'Less than 6 months'
end as EntryDate_status
From p2scflow.debt
Where rep_code LIKE '1%'
Group By rep_group;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Aug 2023 14:26:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Case-when-statement-is-not-showing-the-correct-output/m-p/887495#M39382</guid>
      <dc:creator>Sandeep77</dc:creator>
      <dc:date>2023-08-02T14:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: Case when statement is not showing the correct output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Case-when-statement-is-not-showing-the-correct-output/m-p/887498#M39383</link>
      <description>&lt;P&gt;I think you need to provide example data from p2scflow.debt, and possibly output from proc contents describing the variables used.&lt;/P&gt;
&lt;P&gt;The fact that you show datetime values and truncate by reading with with a Date9 format for your EntryDate variable is a bit suspect. If your actual Entrydate is a datetime then the likely range of values exceeds the interval "month", which would treat EntryDate as a date value, expects and so you actually get missing values for the interval, which do indeed get assigned to "less than 6" as missing is always less than any value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Rerun your SQL and just get the interval returned by the INTCK function instead of that case and look.&lt;/P&gt;
&lt;P&gt;If you get all missing then try&lt;/P&gt;
&lt;PRE&gt; intck('month', datepart( EntryDate), date())&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/391779"&gt;@Sandeep77&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I am running a code and used intck to find the dates which are more than 6 months and which are less than 6 months using case when statement. My code runs fine but in the output it shows all data as less than six months even if it is there for more than six months. Can you please suggest the mistake in the code? Thanks&lt;/P&gt;
&lt;P&gt;I want the output data to show accounts with more than 6 months from&amp;nbsp;EntryDate&amp;nbsp; and which are less than 6 months from&amp;nbsp;EntryDate.&lt;/P&gt;
&lt;P&gt;Sample dataset&lt;/P&gt;
&lt;P&gt;Data Status; &lt;BR /&gt;infile cards expandtabs; &lt;BR /&gt;input rep_group $ Serial client_code $ EntryDate :date9. Entrydatestatus$;&lt;BR /&gt;datalines ; &lt;BR /&gt;742 441844248 SHT1064 28JUL2023:00:00:00.000 Lessthansixmonths&lt;BR /&gt;100 442507166 PAY023 01AUG2022:00:00:00.000 Lessthansixmonths&lt;BR /&gt;125 442552022 PAY023 01AUG2023:00:00:00.000 Lessthansixmonths&lt;BR /&gt;100 442034021 EE07 28JUL2022:00:00:00.000 Lessthansixmonths&lt;BR /&gt;521 443717608 KLAA004 01AUG2023:00:00:00.000 Lessthansixmonths&lt;BR /&gt;; &lt;BR /&gt;run;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table Status AS
Select rep_group,
Serial,
client_code,
EntryDate,
case when intck('month', EntryDate, date()) &amp;gt;= 6 then '6 or more months'
when intck('month', EntryDate, date()) &amp;lt; 6 then 'Less than 6 months'
end as EntryDate_status
From p2scflow.debt
Where rep_code LIKE '1%'
Group By rep_group;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 14:39:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Case-when-statement-is-not-showing-the-correct-output/m-p/887498#M39383</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-02T14:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: Case when statement is not showing the correct output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Case-when-statement-is-not-showing-the-correct-output/m-p/887499#M39384</link>
      <description>&lt;P&gt;Apply your SQL code to the sample data, I cannot reproduce the problem.&amp;nbsp; I.E., the code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Status;
infile cards expandtabs;
input rep_group $ Serial client_code $ EntryDate :date9. Entrydatestatus$;
   format entrydate date9. ;
datalines ;
742 441844248 SHT1064 28JUL2023:00:00:00.000 Lessthansixmonths
100 442507166 PAY023 01AUG2022:00:00:00.000 Lessthansixmonths
125 442552022 PAY023 01AUG2023:00:00:00.000 Lessthansixmonths
100 442034021 EE07 28JUL2022:00:00:00.000 Lessthansixmonths
521 443717608 KLAA004 01AUG2023:00:00:00.000 Lessthansixmonths
;
run;

proc sql;
  create table new_Status AS
  Select rep_group, Serial,  client_code,  EntryDate,
   case 
     when intck('month', EntryDate, date()) &amp;gt;= 6 then '6 or more months'
     when intck('month', EntryDate, date()) &amp;lt; 6 then 'Less than 6 months'
   end as EntryDate_status
   From status      /*p2scflow.debt*/
   /*Where rep_code LIKE '1%'*/
   Group By rep_group;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;yields "6 or more" for the first two, and "less than 6" for the last three obs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perhaps your WHERE subset, which I had to comment-out, may be filtering out all the 6-months-or-more rows.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 14:40:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Case-when-statement-is-not-showing-the-correct-output/m-p/887499#M39384</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-08-02T14:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: Case when statement is not showing the correct output</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Case-when-statement-is-not-showing-the-correct-output/m-p/887507#M39385</link>
      <description>&lt;P&gt;INTCK() is counting interval boundaries between the start value and the target value.&amp;nbsp; When the START&amp;nbsp; value is AFTER the TARGET value then the answer is negative.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looks like you gave INTCK() a datetime value (number of seconds) for the start value and a date value (number of says) as the target value.&amp;nbsp; That is always going to be negative since treating a count of seconds as a count of days is going to result in some date that is way way way in the future since there are 24*60*60 seconds in a day.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Aug 2023 15:07:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Case-when-statement-is-not-showing-the-correct-output/m-p/887507#M39385</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-08-02T15:07:56Z</dc:date>
    </item>
  </channel>
</rss>

