<?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: Global Macro Date Variable Passing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Date-Variable-Passing/m-p/599568#M173089</link>
    <description>&lt;P&gt;To help further your understanding, your code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;year(&amp;amp;time_1mos_ago)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;basically resolves to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;year(19/09/30)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;which is 19 divided by 9 divided by 30 and that is equal to&amp;nbsp;0.0703703704 with integer value being 0. And if you format this, you would get a SAS date value 01jan1960. Taking the year('01jan1960') gives you 1960, which is erroneous. HTH&lt;/P&gt;</description>
    <pubDate>Sat, 26 Oct 2019 21:20:10 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-10-26T21:20:10Z</dc:date>
    <item>
      <title>Global Macro Date Variable Passing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Date-Variable-Passing/m-p/599566#M173087</link>
      <description>&lt;P&gt;I have set the following global macro var:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let time_1mos_ago = %sysfunc(intnx(month,%sysfunc(today()),-1,end),YYMMDDS8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the %put of said variable is:&amp;nbsp;TIME_1MOS_AGO=19/09/30&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is what I want. I would like to use&amp;nbsp;time_1mos_ago elsewhere to choose dates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
   CREATE TABLE EGTASK.QUERY_FOR_OVER_APPEND_0005_0000 AS 
   SELECT t1.billable_id, 
          t1.FltDate, 
          /* year */
            (year(&amp;amp;time_1mos_ago)) AS year
      FROM IBS_COMB.OVER_APPEND t1
      WHERE t1.FltDate &amp;lt;= &amp;amp;time_1mos_ago
      ORDER BY t1.FltDate;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;This resulted in empty output....so I removed the restriction to see if the macro variable was passed through properly. I tested this via the above:&amp;nbsp;&lt;CODE class=" language-sas"&gt;year(&amp;amp;time_1mos_ago)) AS year&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Year came back at 1960 when it should have been 2019.&amp;nbsp; What is missing to ensure that the&amp;nbsp;time_1mos_ago macro variable is passing the date properly so I can use it in many following steps?&lt;/P&gt;</description>
      <pubDate>Sat, 26 Oct 2019 20:47:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Date-Variable-Passing/m-p/599566#M173087</guid>
      <dc:creator>BCNAV</dc:creator>
      <dc:date>2019-10-26T20:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: Global Macro Date Variable Passing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Date-Variable-Passing/m-p/599567#M173088</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/142314"&gt;@BCNAV&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you intend to use the date values as number to extract year from date value etc, you are better off not formatting it and just keeping the computed value as a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So You could use the below to make &lt;STRONG&gt;year function&lt;/STRONG&gt; work&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let time_1mos_ago = %sysfunc(intnx(month,%sysfunc(today()),-1,end));

%put &amp;amp;=time_1mos_ago;

1    %let time_1mos_ago = %sysfunc(intnx(month,%sysfunc(today()),-1,end));
2
3    %put &amp;amp;=time_1mos_ago;
TIME_1MOS_AGO=21822
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;One may get confused&amp;nbsp; %sysfunc with a format&amp;nbsp; merely associates a format like a format statement in a datastep does, however in an open code that's not true, where everything is a text(i.e char)&amp;nbsp; one should be mindful of the fact a result token alphanumeric is always a name token or special token and certainly not a number token at the time compilation done by the word scanner.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 26 Oct 2019 21:06:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Date-Variable-Passing/m-p/599567#M173088</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-26T21:06:32Z</dc:date>
    </item>
    <item>
      <title>Re: Global Macro Date Variable Passing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Date-Variable-Passing/m-p/599568#M173089</link>
      <description>&lt;P&gt;To help further your understanding, your code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;year(&amp;amp;time_1mos_ago)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;basically resolves to&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;year(19/09/30)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;which is 19 divided by 9 divided by 30 and that is equal to&amp;nbsp;0.0703703704 with integer value being 0. And if you format this, you would get a SAS date value 01jan1960. Taking the year('01jan1960') gives you 1960, which is erroneous. HTH&lt;/P&gt;</description>
      <pubDate>Sat, 26 Oct 2019 21:20:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Global-Macro-Date-Variable-Passing/m-p/599568#M173089</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-26T21:20:10Z</dc:date>
    </item>
  </channel>
</rss>

