<?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: how to increment datetime variable with 5 years in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-increment-datetime-variable-with-5-years/m-p/892989#M352740</link>
    <description>&lt;P&gt;Thankyou for your reply.I am still getting missing values and error on this code.Thankyou for noticing todays_date issue&lt;/P&gt;&lt;P&gt;26 proc sql;&lt;BR /&gt;27 create table PRE_QA_PEER as&lt;BR /&gt;28 select a.distinct_load_ts_all as distinct_load_ts&lt;BR /&gt;29 ,a.volume_records_all as volume_records&lt;BR /&gt;30 ,'FCORE_EE.FSC_ENTITY_PEER_GROUP' as table_name&lt;BR /&gt;31 ,%sysfunc(intnx(dtyear,b.distinct_load_ts,&amp;amp;rtncd.,s))&lt;BR /&gt;SYMBOLGEN: Macro variable RTNCD resolves to 5&lt;BR /&gt;&lt;STRONG&gt;ERROR: Argument 2 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list.&lt;/STRONG&gt; Execution of %SYSCALL statement or %SYSFUNC or %QSYSFUNC function reference is terminated.&lt;BR /&gt;32 as aged_out format datetime19.&lt;BR /&gt;33 ,&amp;amp;today_date. as today_date&lt;BR /&gt;SYMBOLGEN: Macro variable TODAY_DATE resolves to '2023-09-05 18:56:07'&lt;BR /&gt;34 ,case when a.distinct_load_ts_all = b.distinct_load_ts then 'Y'&lt;BR /&gt;35 else 'N'&lt;BR /&gt;36 end as flag_to_delete from&lt;BR /&gt;37 (select distinct_load_ts_all,volume_records_all from VLM_BEFORE_PEER) a&lt;BR /&gt;38 left join&lt;BR /&gt;39 (select distinct_load_ts from CNT_DLT_VLMS) b&lt;BR /&gt;40 on a.distinct_load_ts_all = b.distinct_load_ts;&lt;BR /&gt;NOTE: Table WORK.PRE_QA_PEER created, with 903 rows and 6 columns.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Sep 2023 17:04:06 GMT</pubDate>
    <dc:creator>Coco_08</dc:creator>
    <dc:date>2023-09-06T17:04:06Z</dc:date>
    <item>
      <title>how to increment datetime variable with 5 years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-increment-datetime-variable-with-5-years/m-p/892901#M352692</link>
      <description>&lt;P&gt;Hi,Below is the code from teradata passthrough that i am trying to convert to proc sql.Could you please help and let me know how to use the highlighted increment code.I tried intnx() but it is not working and giving me missing values.Thankyou&lt;/P&gt;&lt;DIV&gt;proc sql;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;create table PRE_QA_&amp;amp;v2. as&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;select distinct b.distinct_load_ts,&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;b.volume_records,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;amp;tn. as table_name,&lt;/DIV&gt;&lt;DIV&gt;&lt;STRONG&gt;b.distinct_load_ts&amp;nbsp; + &amp;amp;rtncd. * interval '1' year as aged_out,&lt;/STRONG&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&amp;amp;today_date.&amp;nbsp; as today_date,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;case when a.&amp;amp;v. = b.&amp;amp;v. then 'Y'&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else 'N'&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end&amp;nbsp; &amp;nbsp;as flag_to_delete&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; from (select distinct_load_ts,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;volume_records,&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;volume_before,&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp;&amp;amp;v.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; from vlm_before_&amp;amp;v2. ) b&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;left join&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;dist_ts_all_&amp;amp;v2.&amp;nbsp; a&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;on a.&amp;amp;v. = b.&amp;amp;v.;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;quit;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 11:25:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-increment-datetime-variable-with-5-years/m-p/892901#M352692</guid>
      <dc:creator>Coco_08</dc:creator>
      <dc:date>2023-09-06T11:25:57Z</dc:date>
    </item>
    <item>
      <title>Re: how to increment datetime variable with 5 years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-increment-datetime-variable-with-5-years/m-p/892903#M352693</link>
      <description>&lt;P&gt;If all your source tables are in Teradata and you've got already working Teradata SQL then why don't you just use explicit pass-through SLQ because then you don't have to change your code.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 11:45:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-increment-datetime-variable-with-5-years/m-p/892903#M352693</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2023-09-06T11:45:01Z</dc:date>
    </item>
    <item>
      <title>Re: how to increment datetime variable with 5 years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-increment-datetime-variable-with-5-years/m-p/892904#M352694</link>
      <description>&lt;P&gt;Your INTNX should look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;intnx("dtyear",b.distinct_load_ts,&amp;amp;rtncd.,"s") as aged_out,&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Sep 2023 11:42:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-increment-datetime-variable-with-5-years/m-p/892904#M352694</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-06T11:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to increment datetime variable with 5 years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-increment-datetime-variable-with-5-years/m-p/892913#M352699</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;26 proc sql;&lt;BR /&gt;27 create table PRE_QA_PEER as&lt;BR /&gt;28 select a.distinct_load_ts_all as distinct_load_ts&lt;BR /&gt;29 ,a.volume_records_all as volume_records&lt;BR /&gt;30 ,'FCORE_EE.FSC_ENTITY_PEER_GROUP' as table_name&lt;BR /&gt;31 , %sysfunc(intnx("dtyear",b.distinct_load_ts,&amp;amp;rtncd.,"s")) as aged_out&lt;BR /&gt;SYMBOLGEN: Macro variable RTNCD resolves to 5&lt;BR /&gt;ERROR: Argument 2 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.&lt;BR /&gt;ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC or %QSYSFUNC function reference is terminated.&lt;BR /&gt;32 ,"&amp;amp;today_date" as today_date&lt;BR /&gt;SYMBOLGEN: Macro variable TODAY_DATE resolves to '2023-09-05 18:56:07'&lt;BR /&gt;33 ,case when a.distinct_load_ts_all = b.distinct_load_ts then 'Y'&lt;BR /&gt;34 else 'N'&lt;BR /&gt;35 end as flag_to_delete from&lt;BR /&gt;36 (select distinct_load_ts_all,volume_records_all from VLM_BEFORE_PEER) a&lt;BR /&gt;37 left join&lt;BR /&gt;38 (select distinct_load_ts from CNT_DLT_VLMS) b&lt;BR /&gt;39 on a.distinct_load_ts_all = b.distinct_load_ts;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 12:06:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-increment-datetime-variable-with-5-years/m-p/892913#M352699</guid>
      <dc:creator>Coco_08</dc:creator>
      <dc:date>2023-09-06T12:06:44Z</dc:date>
    </item>
    <item>
      <title>Re: how to increment datetime variable with 5 years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-increment-datetime-variable-with-5-years/m-p/892918#M352701</link>
      <description>&lt;P&gt;The INTNX() function does not understand the interval name of "dtyear" that the %SYSFUNC() macro function passed to it.&amp;nbsp; It was expecting a value like dtyear instead. Remove the quotes from your macro code so that they do not become part of the strings passed to the SAS function.&amp;nbsp; In macro code you do not need to enclose string literals in quotes because everything is a string to the macro processor.&amp;nbsp; The macro processor is just looking the &amp;amp; and % characters to know when it should take action and modify your SAS code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also you probably will want to attach a FORMAT to your new variable so humans can recognize the number of seconds as an actual datetime value.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;, %sysfunc(intnx(dtyear,b.distinct_load_ts,&amp;amp;rtncd.,s)) as aged_out&amp;nbsp;format=datetime19.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Plus did you really want to make variable TODAY_DATE as a character string with single quotes in it?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looks you ran&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;, "'2023-09-05 18:56:07'" as today_date&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There are a lot of problems with that.&amp;nbsp; The name implies that it has a DATE value.&amp;nbsp; But instead if has a datetime value represent as a string including enclosing quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to make another datetime variable then I would recommend using a different name and using the macro variable to generate a datetime constant. Again if you want the number of seconds to print so humans can understand then attach an appropriate display format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; ,&amp;amp;today_date.dt as today_datetime format=datetime19.&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Sep 2023 12:47:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-increment-datetime-variable-with-5-years/m-p/892918#M352701</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-06T12:47:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to increment datetime variable with 5 years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-increment-datetime-variable-with-5-years/m-p/892989#M352740</link>
      <description>&lt;P&gt;Thankyou for your reply.I am still getting missing values and error on this code.Thankyou for noticing todays_date issue&lt;/P&gt;&lt;P&gt;26 proc sql;&lt;BR /&gt;27 create table PRE_QA_PEER as&lt;BR /&gt;28 select a.distinct_load_ts_all as distinct_load_ts&lt;BR /&gt;29 ,a.volume_records_all as volume_records&lt;BR /&gt;30 ,'FCORE_EE.FSC_ENTITY_PEER_GROUP' as table_name&lt;BR /&gt;31 ,%sysfunc(intnx(dtyear,b.distinct_load_ts,&amp;amp;rtncd.,s))&lt;BR /&gt;SYMBOLGEN: Macro variable RTNCD resolves to 5&lt;BR /&gt;&lt;STRONG&gt;ERROR: Argument 2 to function INTNX referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number.&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list.&lt;/STRONG&gt; Execution of %SYSCALL statement or %SYSFUNC or %QSYSFUNC function reference is terminated.&lt;BR /&gt;32 as aged_out format datetime19.&lt;BR /&gt;33 ,&amp;amp;today_date. as today_date&lt;BR /&gt;SYMBOLGEN: Macro variable TODAY_DATE resolves to '2023-09-05 18:56:07'&lt;BR /&gt;34 ,case when a.distinct_load_ts_all = b.distinct_load_ts then 'Y'&lt;BR /&gt;35 else 'N'&lt;BR /&gt;36 end as flag_to_delete from&lt;BR /&gt;37 (select distinct_load_ts_all,volume_records_all from VLM_BEFORE_PEER) a&lt;BR /&gt;38 left join&lt;BR /&gt;39 (select distinct_load_ts from CNT_DLT_VLMS) b&lt;BR /&gt;40 on a.distinct_load_ts_all = b.distinct_load_ts;&lt;BR /&gt;NOTE: Table WORK.PRE_QA_PEER created, with 903 rows and 6 columns.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 17:04:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-increment-datetime-variable-with-5-years/m-p/892989#M352740</guid>
      <dc:creator>Coco_08</dc:creator>
      <dc:date>2023-09-06T17:04:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to increment datetime variable with 5 years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-increment-datetime-variable-with-5-years/m-p/893002#M352747</link>
      <description>&lt;P&gt;You are using macro code to generate a CONSTANT date.&amp;nbsp; You are trying base the date off of the constant string&amp;nbsp;b.distinct_load_ts which is not a date.&amp;nbsp; Instead it is a string you would use as part of an SQL statement to reference a variable from a dataset that you have refered to with the alias B.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that is what you need to get rid of the macro code and just call the actual SAS function INTNX() directly.&amp;nbsp; Now it can run for each individual value of&amp;nbsp;&lt;SPAN&gt;b.distinct_load_ts instead of having the macro processor generate a constant date value.&amp;nbsp; Since you now writing SAS conde instead of using macro code to write the SAS code you need to enclose the string literals in quotes so SAS does not assume you are referring to&amp;nbsp;variables named DTYEAR and S&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;, intnx('dtyear',b.distinct_load_ts,&amp;amp;rtncd.,'s') as aged_out format=datetime19.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 17:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-increment-datetime-variable-with-5-years/m-p/893002#M352747</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-09-06T17:29:51Z</dc:date>
    </item>
    <item>
      <title>Re: how to increment datetime variable with 5 years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-increment-datetime-variable-with-5-years/m-p/893012#M352755</link>
      <description>&lt;P&gt;Please&amp;nbsp;&lt;STRONG&gt;&lt;U&gt;READ&lt;/U&gt;&lt;/STRONG&gt; my post, with diligence. There is no %SYSFUNC in it.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Sep 2023 18:13:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-increment-datetime-variable-with-5-years/m-p/893012#M352755</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-09-06T18:13:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to increment datetime variable with 5 years</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-increment-datetime-variable-with-5-years/m-p/893068#M352776</link>
      <description>&lt;P&gt;Thankyou so much.it works.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Sep 2023 05:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-increment-datetime-variable-with-5-years/m-p/893068#M352776</guid>
      <dc:creator>Coco_08</dc:creator>
      <dc:date>2023-09-07T05:09:36Z</dc:date>
    </item>
  </channel>
</rss>

