<?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: Date macro from calculation in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Date-macro-from-calculation/m-p/791763#M253673</link>
    <description>&lt;P&gt;I don't see the need to use a macro at all. Why can't you use&lt;/P&gt;
&lt;PRE&gt;mnth_1 = intnx('month', &amp;amp;myDT., -1, 's');&lt;/PRE&gt;
&lt;P&gt;in a data step? &lt;/P&gt;</description>
    <pubDate>Mon, 24 Jan 2022 06:48:43 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2022-01-24T06:48:43Z</dc:date>
    <item>
      <title>Date macro from calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-macro-from-calculation/m-p/791718#M253641</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the below program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let myDT = '23JAN2022'D;

%macro dts(mnth_1=);
	data want;
		test_dt=&amp;amp;mnth_1.;
		format test_dt date9.;
	run;

	%put @@@&amp;amp;myDT;
	%put @@@&amp;amp;mnth_1;
%mend;

%dts(mnth_1=intnx('month', &amp;amp;myDT., -1, 's'));&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Initially, I have the macro variable&lt;/P&gt;
&lt;PRE&gt;&amp;amp;myDT.&lt;/PRE&gt;
&lt;P&gt;which I pass it to the macro&lt;/P&gt;
&lt;PRE&gt;%dts(mnth_1=intnx('month', &amp;amp;myDT., -1, 's'))&lt;/PRE&gt;
&lt;P&gt;in order to find last month's date.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Even though I am able to use the&lt;/P&gt;
&lt;PRE&gt;&amp;amp;mnth_1.&lt;/PRE&gt;
&lt;P&gt;in order to create the dataset,&amp;nbsp;when I use the&lt;/P&gt;
&lt;PRE&gt;%PUT&lt;/PRE&gt;
&lt;P&gt;statement to write the value it doesn't work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any ideas please?&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jan 2022 16:58:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-macro-from-calculation/m-p/791718#M253641</guid>
      <dc:creator>Zatere</dc:creator>
      <dc:date>2022-01-23T16:58:01Z</dc:date>
    </item>
    <item>
      <title>Re: Date macro from calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-macro-from-calculation/m-p/791722#M253644</link>
      <description>&lt;P&gt;As a first step, please define what the purpose of the macro should be.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jan 2022 17:45:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-macro-from-calculation/m-p/791722#M253644</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-23T17:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: Date macro from calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-macro-from-calculation/m-p/791724#M253646</link>
      <description>The macro mnth_1=intnx('month', &amp;amp;myDT., -1, 's') is used to create a variable in an existing dataset.&lt;BR /&gt;As you might have seen, this part of the program works as expected.&lt;BR /&gt;However, I would like to write the &amp;amp;mnth_1. &lt;BR /&gt;Is that possible?&lt;BR /&gt;Thanks.</description>
      <pubDate>Sun, 23 Jan 2022 17:58:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-macro-from-calculation/m-p/791724#M253646</guid>
      <dc:creator>Zatere</dc:creator>
      <dc:date>2022-01-23T17:58:12Z</dc:date>
    </item>
    <item>
      <title>Re: Date macro from calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-macro-from-calculation/m-p/791726#M253648</link>
      <description>&lt;P&gt;I'm going to avoid the macro %dts and just create a macro variable named &amp;amp;dts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let dts=%nrstr(mnth_1=intnx('month', &amp;amp;myDT., -1, 's'));
%put &amp;amp;=dts;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can use &amp;amp;DTS anywhere you want. As to why you want this, I still don't understand, and I get the feeling you have over-complicated things.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also do this to create macro variable &amp;amp;MNTH_1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mnth1 = %sysfunc(intnx(month,&amp;amp;mydt,-1,s));&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So, please explain in much more detail what you want, why you want it, and even better ... give us an example of what you are doing without macros and without macro variables. As I said, I think you have greatly over-complicated things.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jan 2022 19:38:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-macro-from-calculation/m-p/791726#M253648</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-01-23T19:38:17Z</dc:date>
    </item>
    <item>
      <title>Re: Date macro from calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-macro-from-calculation/m-p/791727#M253649</link>
      <description>&lt;P&gt;mnth_1 is a&amp;nbsp;&lt;EM&gt;macro parameter&lt;/EM&gt;, not a &lt;EM&gt;macro&lt;/EM&gt;. What is the purpose of the&amp;nbsp;&lt;EM&gt;macro&lt;/EM&gt; dts?&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jan 2022 20:38:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-macro-from-calculation/m-p/791727#M253649</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-01-23T20:38:12Z</dc:date>
    </item>
    <item>
      <title>Re: Date macro from calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-macro-from-calculation/m-p/791736#M253652</link>
      <description>&lt;P&gt;To print the value of a VARIABLE use the PUT statement.&amp;nbsp; The %PUT statement is a MACRO STATEMENT and so will know nothing about any variables you might have created in your data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro dts(mnth_1=);

%put &amp;amp;=mnth_1;
data want;
  test_dt=&amp;amp;mnth_1.;
  format test_dt date9.;
  put test_dt = ;
run;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Let's try it:&lt;/P&gt;
&lt;PRE&gt;2106  %let myDT = '23JAN2022'D;
2107  %dts(mnth_1=intnx('month', &amp;amp;myDT., -1, 's'));
MNTH_1=intnx('month', '23JAN2022'D, -1, 's')
MPRINT(DTS):   data want;
MPRINT(DTS):   test_dt=intnx('month', '23JAN2022'D, -1, 's');
MPRINT(DTS):   format test_dt date9.;
MPRINT(DTS):   put test_dt = ;
MPRINT(DTS):   run;

test_dt=23DEC2021
NOTE: The data set WORK.WANT has 1 observations and 1 variables.
&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Jan 2022 22:40:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-macro-from-calculation/m-p/791736#M253652</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-23T22:40:57Z</dc:date>
    </item>
    <item>
      <title>Re: Date macro from calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-macro-from-calculation/m-p/791763#M253673</link>
      <description>&lt;P&gt;I don't see the need to use a macro at all. Why can't you use&lt;/P&gt;
&lt;PRE&gt;mnth_1 = intnx('month', &amp;amp;myDT., -1, 's');&lt;/PRE&gt;
&lt;P&gt;in a data step? &lt;/P&gt;</description>
      <pubDate>Mon, 24 Jan 2022 06:48:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-macro-from-calculation/m-p/791763#M253673</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2022-01-24T06:48:43Z</dc:date>
    </item>
    <item>
      <title>Re: Date macro from calculation</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Date-macro-from-calculation/m-p/791790#M253679</link>
      <description>Thank you very much.&lt;BR /&gt;I was hoping that I can use the %PUT statement.&lt;BR /&gt;However, your solution does what I wanted, meaning to print the value.</description>
      <pubDate>Mon, 24 Jan 2022 08:37:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Date-macro-from-calculation/m-p/791790#M253679</guid>
      <dc:creator>Zatere</dc:creator>
      <dc:date>2022-01-24T08:37:22Z</dc:date>
    </item>
  </channel>
</rss>

