<?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: Intck does not give the desired output in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Intck-does-not-give-the-desired-output/m-p/858475#M339189</link>
    <description>&lt;P&gt;You aren't specifying the macro date correctly. Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select min(final_date) format=date9.
  into :min_dt
  from master1;
quit;
%put &amp;amp;min_dt; /*min_dt is set to 04/11/2022*/

data master1_1;
set master1;
   days=intck('day', "&amp;amp;min_dt"d, final_date);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 13 Feb 2023 06:23:34 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2023-02-13T06:23:34Z</dc:date>
    <item>
      <title>Intck does not give the desired output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intck-does-not-give-the-desired-output/m-p/858470#M339187</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm trying to create a variable, days, that stores the amount of days from the minimum date extracted from the date variable on my dataset. I stored the min date to a macro variable, min_dt , and tried to use it in intck to calculate the number of days in comparing to the values in final_date:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;proc sql;
select min(final_date) format=MMDDYY10.
  into :min_dt
  from master1;
quit;
%put &amp;amp;min_dt; /*min_dt is set to 04/11/2022*/

data master1_1;
set master1;
   days=intck('day', &amp;amp;min_dt, final_date);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Somehow, I'm not getting the desired days. The output looks like this:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR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;&lt;TD&gt;&lt;P&gt;&lt;SPAN&gt;4/26/2022&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;SPAN&gt;22761&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;&lt;SPAN&gt;4/27/2022&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;&lt;SPAN&gt;22762&lt;/SPAN&gt;&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Final_date is in&amp;nbsp;&lt;CODE class=""&gt;MMDDYY10&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Anyone knows what the problem is?&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 04:12:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intck-does-not-give-the-desired-output/m-p/858470#M339187</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2023-02-13T04:12:56Z</dc:date>
    </item>
    <item>
      <title>Re: Intck does not give the desired output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intck-does-not-give-the-desired-output/m-p/858475#M339189</link>
      <description>&lt;P&gt;You aren't specifying the macro date correctly. Try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select min(final_date) format=date9.
  into :min_dt
  from master1;
quit;
%put &amp;amp;min_dt; /*min_dt is set to 04/11/2022*/

data master1_1;
set master1;
   days=intck('day', "&amp;amp;min_dt"d, final_date);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Feb 2023 06:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intck-does-not-give-the-desired-output/m-p/858475#M339189</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2023-02-13T06:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: Intck does not give the desired output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intck-does-not-give-the-desired-output/m-p/858477#M339190</link>
      <description>&lt;P&gt;Just don't use a format at all, when storing dates in macro variables, if you don't want to use them in titles, footnotes etc.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 07:28:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intck-does-not-give-the-desired-output/m-p/858477#M339190</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2023-02-13T07:28:21Z</dc:date>
    </item>
    <item>
      <title>Re: Intck does not give the desired output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intck-does-not-give-the-desired-output/m-p/858486#M339197</link>
      <description>&lt;P&gt;Maxim 28: Macro Variables Need No Formats.&lt;/P&gt;
&lt;P&gt;Raw values are easier to use in code.&lt;/P&gt;
&lt;P&gt;When your macro variable is resolved, you get this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data master1_1;
set master1;
   days=intck('day', 04/11/2022, final_date);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;4 divided by 11 divided by 2022 (this is the &lt;EM&gt;formula&lt;/EM&gt; SAS sees)&amp;nbsp;is a value very close to zero, so you get the count of days from the SAS zero point, which is 1960-01-01.&lt;/P&gt;
&lt;P&gt;You also do not need INTCK when calculating a date difference in days, as SAS date values are integer&amp;nbsp;&lt;EM&gt;counts of days&lt;/EM&gt;.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select min(final_date)
  into :min_dt
  from master1
;
quit;

data master1_1;
set master1;
days = final_date - &amp;amp;min_dt.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you can do this in one step:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data master1_1;
min_dt = '31dec9999'd;
do until (end1);
  set master1 end=end1;
  min_dt = min(min_dt,final_date);
end;
do until (end2);
  set master1 end=end2;
  days = final_date - min_dt;
  output;
end;
drop min_dt;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table master1_1 as
  select
    *,
    final_date - (select min(final_date) from master1) as days
  from master1
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Codes untested, posted from my tablet.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 09:43:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intck-does-not-give-the-desired-output/m-p/858486#M339197</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-02-13T09:43:15Z</dc:date>
    </item>
    <item>
      <title>Re: Intck does not give the desired output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Intck-does-not-give-the-desired-output/m-p/858522#M339213</link>
      <description>&lt;P&gt;Maybe this bit of code will help understand exactly what happened.&lt;/P&gt;
&lt;P&gt;I set the macro variable to your example "date" and use today() function to have a date to compare with.&lt;/P&gt;
&lt;PRE&gt;%let min_dt=01/11/2022;

data example;
   x=  &amp;amp;min_dt.;
   days=intck('day', &amp;amp;min_dt., today());
   days2= intck('day',0,today());
   format days days2 date9.;
run;&lt;/PRE&gt;
&lt;P&gt;Since you did not provide a proper date value but the formatted string 01/11/2022 then SAS interpreted that string as an instruction to divide 01 by 11 and then divide that result by 2022 giving a value much less than 1. So the "date" used by the INTCK function was essentially 0 as dates are not supposed to a fractional component and returned the date fo the second parameter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/ta-p/424354&lt;/A&gt; has a PDF with much information about dates.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Feb 2023 16:28:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Intck-does-not-give-the-desired-output/m-p/858522#M339213</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-13T16:28:55Z</dc:date>
    </item>
  </channel>
</rss>

