<?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: correction of macrocode needed in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/correction-of-macrocode-needed/m-p/692518#M24913</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281554"&gt;@PierreYvesILY&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;hello Paige,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm a SAS new user, and I don't know much about macrocode.&lt;/P&gt;
&lt;P&gt;%superq and&amp;nbsp;%qsysfunc are functions I don't know at all.&lt;/P&gt;
&lt;P&gt;Finally, what I Need is :&lt;/P&gt;
&lt;P&gt;1. a macro Monat where the month as a 'number' is saved : for instance: January =1 and December = 12.&lt;/P&gt;
&lt;P&gt;The &amp;amp;Monat. has to be the month BEFORE the &amp;amp;Auswertungstag.&lt;/P&gt;
&lt;P&gt;therefore:&amp;nbsp;if &amp;amp;Auswertungstag.&amp;nbsp;= '01JAN2021'D =&amp;gt; &amp;amp;Monat. = 12&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So, this is not the original problem. It really helps if you state the actual problem in your original message, rather than changing it after we have worked on your problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let Auswertungstag = %sysevalf('01JAN2020'd); *Bei Bedarf: Datum vorgeben;
%let previous_month = %sysfunc(intnx(month,&amp;amp;Auswertungstag,-1,b));
%let year=%sysfunc(year(&amp;amp;previous_month));
%let month=%sysfunc(month(&amp;amp;previous_month));

%put &amp;amp;=Auswertungstag;
%put &amp;amp;=previous_month;
%put &amp;amp;=year;
%put &amp;amp;=month;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;An important point here, whenever you deal with calendar dates is to represent the data as a valid SAS date, which means the number of days since January 1, 1960. So, January 1, 2020 is represented as 21915. Then you can find the previous month using the INTNX function, so you don't have to write your own code that knows what month comes before any specified month, SAS has already created a function to do this.&lt;/P&gt;</description>
    <pubDate>Mon, 19 Oct 2020 13:37:18 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2020-10-19T13:37:18Z</dc:date>
    <item>
      <title>correction of macrocode needed</title>
      <link>https://communities.sas.com/t5/New-SAS-User/correction-of-macrocode-needed/m-p/692489#M24899</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;my Code:&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Auswertungstag = '01OCT2020'D; &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008000"&gt;*Bei Bedarf: Datum vorgeben;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Spanne=9; &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008000"&gt;*Spanne: Anzahl der Monate des Dashboardszeitraum;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#008000"&gt;*Der Monatszeitraum fängt an, mit dem Vormonat von dem Auswertungstag;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Monat= &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%eval&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(%month(&amp;amp;Auswertungstag.)); &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Jahr1= &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%eval&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(%year(&amp;amp;Auswertungstag.)); &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Jahr2= &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%eval&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;Jahr1.-1);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;Auswertungstag.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;Spanne.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;Monat.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;Jahr1.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;Jahr2.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get following Errors in the log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;GOPTIONS ACCESSIBLE;&lt;/P&gt;&lt;P&gt;27 %let Auswertungstag = '01OCT2020'D;&lt;/P&gt;&lt;P&gt;28 %let Spanne=9;&lt;/P&gt;&lt;P&gt;29&lt;/P&gt;&lt;P&gt;30 %let Monat= %eval(%month(&amp;amp;Auswertungstag.));&lt;/P&gt;&lt;P&gt;31 %let Jahr1= %eval(%year(&amp;amp;Auswertungstag.));&lt;/P&gt;&lt;P&gt;NOTE: The quoted string currently being processed has become more than 262 bytes long. You might have unbalanced quotation marks.&lt;/P&gt;&lt;P&gt;32 %let Jahr2= %eval(&amp;amp;Jahr1.-1);&lt;/P&gt;&lt;P&gt;33 %put &amp;amp;Auswertungstag.;&lt;/P&gt;&lt;P&gt;34 %put &amp;amp;Spanne.;&lt;/P&gt;&lt;P&gt;35 %put &amp;amp;Monat.;&lt;/P&gt;&lt;P&gt;36 %put &amp;amp;Jahr1.;&lt;/P&gt;&lt;P&gt;37 %put &amp;amp;Jahr2.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why is there no result in the log after the %put Statement?&lt;/P&gt;&lt;P&gt;it seems it doesn't calculate anything.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I correct this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 11:50:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/correction-of-macrocode-needed/m-p/692489#M24899</guid>
      <dc:creator>PierreYvesILY</dc:creator>
      <dc:date>2020-10-19T11:50:33Z</dc:date>
    </item>
    <item>
      <title>Re: correction of macrocode needed</title>
      <link>https://communities.sas.com/t5/New-SAS-User/correction-of-macrocode-needed/m-p/692490#M24900</link>
      <description>&lt;P&gt;I get different errors in the LOG when I run this exact code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no such thing as a %MONTH or %YEAR macro function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But this works, keeping in mind &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/Maxims-of-Maximally-Efficient-SAS-Programmers/ta-p/352068" target="_self"&gt;Maxim 28&lt;/A&gt; which says you should not format macro variables (so &amp;amp;Auswertungstag is not formatted)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let Auswertungstag = %sysevalf('01OCT2020'd); *Bei Bedarf: Datum vorgeben;
%let Spanne=9; *Spanne: Anzahl der Monate des Dashboardszeitraum;
*Der Monatszeitraum fängt an, mit dem Vormonat von dem Auswertungstag;
%let Monat= %sysfunc(month(&amp;amp;Auswertungstag.));
%let Jahr1= %sysfunc(year(&amp;amp;Auswertungstag.));
%let Jahr2= %eval(&amp;amp;Jahr1.-1);
%put &amp;amp;=Auswertungstag.;
%put &amp;amp;=Spanne.;
%put &amp;amp;=Monat.;
%put &amp;amp;=Jahr1.;
%put &amp;amp;=Jahr2.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 11:58:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/correction-of-macrocode-needed/m-p/692490#M24900</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-19T11:58:12Z</dc:date>
    </item>
    <item>
      <title>Re: correction of macrocode needed</title>
      <link>https://communities.sas.com/t5/New-SAS-User/correction-of-macrocode-needed/m-p/692494#M24901</link>
      <description>&lt;P&gt;hallo Paige,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've got the following error messages ; is it possible, that it is due to SAS 9.3?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;43 %let Auswertungstag = %sysevalf('01OCT2020'd); *Bei Bedarf: Datum vorgeben;&lt;/P&gt;&lt;P&gt;ERROR: Open code statement recursion detected.&lt;/P&gt;&lt;P&gt;44 %let Spanne=9; *Spanne: Anzahl der Monate des Dashboardszeitraum;&lt;/P&gt;&lt;P&gt;ERROR: Open code statement recursion detected.&lt;/P&gt;&lt;P&gt;45 *Der Monatszeitraum fängt an, mit dem Vormonat von dem Auswertungstag;&lt;/P&gt;&lt;P&gt;46 %let Monat= %sysfunc(month(&amp;amp;Auswertungstag.));&lt;/P&gt;&lt;P&gt;ERROR: Open code statement recursion detected.&lt;/P&gt;&lt;P&gt;47 %let Jahr1= %sysfunc(year(&amp;amp;Auswertungstag.));&lt;/P&gt;&lt;P&gt;ERROR: Open code statement recursion detected.&lt;/P&gt;&lt;P&gt;2 The SAS System 13:41 Monday, October 19, 2020&lt;/P&gt;&lt;P&gt;48 %let Jahr2= %eval(&amp;amp;Jahr1.-1);&lt;/P&gt;&lt;P&gt;ERROR: Open code statement recursion detected.&lt;/P&gt;&lt;P&gt;49 %put &amp;amp;=Auswertungstag.;&lt;/P&gt;&lt;P&gt;ERROR: Open code statement recursion detected.&lt;/P&gt;&lt;P&gt;50 %put &amp;amp;=Spanne.;&lt;/P&gt;&lt;P&gt;ERROR: Open code statement recursion detected.&lt;/P&gt;&lt;P&gt;51 %put &amp;amp;=Monat.;&lt;/P&gt;&lt;P&gt;ERROR: Open code statement recursion detected.&lt;/P&gt;&lt;P&gt;52 %put &amp;amp;=Jahr1.;&lt;/P&gt;&lt;P&gt;ERROR: Open code statement recursion detected.&lt;/P&gt;&lt;P&gt;53 %put &amp;amp;=Jahr2.;&lt;/P&gt;&lt;P&gt;ERROR: Open code statement recursion detected.&lt;/P&gt;&lt;P&gt;54&lt;/P&gt;&lt;P&gt;55 GOPTIONS NOACCESSIBLE;&lt;/P&gt;&lt;P&gt;56 %LET _CLIENTTASKLABEL=;&lt;/P&gt;&lt;P&gt;ERROR: Open code statement recursion detected.&lt;/P&gt;&lt;P&gt;57 %LET _CLIENTPROCESSFLOWNAME=;&lt;/P&gt;&lt;P&gt;ERROR: Open code statement recursion detected.&lt;/P&gt;&lt;P&gt;58 %LET _CLIENTPROJECTPATH=;&lt;/P&gt;&lt;P&gt;ERROR: Open code statement recursion detected.&lt;/P&gt;&lt;P&gt;59 %LET _CLIENTPROJECTPATHHOST=;&lt;/P&gt;&lt;P&gt;ERROR: Open code statement recursion detected.&lt;/P&gt;&lt;P&gt;60 %LET _CLIENTPROJECTNAME=;&lt;/P&gt;&lt;P&gt;ERROR: Open code statement recursion detected.&lt;/P&gt;&lt;P&gt;61 %LET _SASPROGRAMFILE=;&lt;/P&gt;&lt;P&gt;ERROR: Open code statement recursion detected.&lt;/P&gt;&lt;P&gt;62 %LET _SASPROGRAMFILEHOST=;&lt;/P&gt;&lt;P&gt;ERROR: Open code statement recursion detected.&lt;/P&gt;&lt;P&gt;63&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 12:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/correction-of-macrocode-needed/m-p/692494#M24901</guid>
      <dc:creator>PierreYvesILY</dc:creator>
      <dc:date>2020-10-19T12:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: correction of macrocode needed</title>
      <link>https://communities.sas.com/t5/New-SAS-User/correction-of-macrocode-needed/m-p/692497#M24902</link>
      <description>&lt;P&gt;What happens if you close SAS, and then re-start it and run the code I showed?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 13:10:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/correction-of-macrocode-needed/m-p/692497#M24902</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-19T13:10:09Z</dc:date>
    </item>
    <item>
      <title>Re: correction of macrocode needed</title>
      <link>https://communities.sas.com/t5/New-SAS-User/correction-of-macrocode-needed/m-p/692501#M24903</link>
      <description>&lt;P&gt;From the last SAS log you sent I can see you're using Enterprise Guide to write your SAS code. The "open code recursion" error most frequently occurs when a macro statement has previously been submitted without a semicolon. Try resetting your SAS session an submitting this code from a fresh SAS session:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro month(sasdate);
%qsysfunc(month(%superq(sasdate)))
%mend;

%macro year(sasdate);
%qsysfunc(year(%superq(sasdate)))
%mend;

%let Auswertungstag = '01OCT2020'D; *Bei Bedarf: Datum vorgeben;
%let Spanne=9; *Spanne: Anzahl der Monate des Dashboardszeitraum;
*Der Monatszeitraum fängt an, mit dem Vormonat von dem Auswertungstag;
%let Monat= %eval(%month(&amp;amp;Auswertungstag.));
%let Jahr1= %eval(%year(&amp;amp;Auswertungstag.));
%let Jahr2= %eval(&amp;amp;Jahr1.-1);
%put NOTE: &amp;amp;=Auswertungstag.;
%put NOTE: &amp;amp;=Spanne. &amp;amp;=Monat. &amp;amp;=Jahr1. &amp;amp;=Jahr2.;
%put NOTE: Subnmitted from &amp;amp;_CLIENTAPP version &amp;amp;_CLIENTVERSION;
%put NOTE- Running on SAS version &amp;amp;sysvlong;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This code runs without error or warnings for me from Enterprise Guide 8.2 running SAS 9.4M7.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The last two lines should provide &lt;EM&gt;your&lt;/EM&gt; Enterprise Guide and SAS version information, which might be helpful if further troubleshooting is necessary.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 12:47:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/correction-of-macrocode-needed/m-p/692501#M24903</guid>
      <dc:creator>SASJedi</dc:creator>
      <dc:date>2020-10-19T12:47:27Z</dc:date>
    </item>
    <item>
      <title>Re: correction of macrocode needed</title>
      <link>https://communities.sas.com/t5/New-SAS-User/correction-of-macrocode-needed/m-p/692505#M24905</link>
      <description>&lt;UL&gt;
&lt;LI&gt;Why do you need %superq here?&lt;/LI&gt;
&lt;LI&gt;Why do you need %qsysfunc instead of %sysfunc? (Month and year values should not require any macro quoting)&lt;/LI&gt;
&lt;LI&gt;Why do you need&amp;nbsp;%eval(%month(&amp;amp;Auswertungstag.)) instead of&amp;nbsp;%month(&amp;amp;Auswertungstag.)?&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;The code work properly without %superq and without %eval and with %sysfunc instead of %qsysfunc&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 13:03:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/correction-of-macrocode-needed/m-p/692505#M24905</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-19T13:03:26Z</dc:date>
    </item>
    <item>
      <title>Re: correction of macrocode needed</title>
      <link>https://communities.sas.com/t5/New-SAS-User/correction-of-macrocode-needed/m-p/692512#M24909</link>
      <description>&lt;P&gt;hello Paige,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm a SAS new user, and I don't know much about macrocode.&lt;/P&gt;&lt;P&gt;%superq and&amp;nbsp;%qsysfunc are functions I don't know at all.&lt;/P&gt;&lt;P&gt;Finally, what I Need is :&lt;/P&gt;&lt;P&gt;1. a macro Monat where the month as a 'number' is saved : for instance: January =1 and December = 12.&lt;/P&gt;&lt;P&gt;The &amp;amp;Monat. has to be the month BEFORE the &amp;amp;Auswertungstag.&lt;/P&gt;&lt;P&gt;therefore:&amp;nbsp;if &amp;amp;Auswertungstag.&amp;nbsp;= '01JAN2021'D =&amp;gt; &amp;amp;Monat. = 12&lt;/P&gt;&lt;P&gt;2. a macro Jahr1 where the year of that given monat is stored.&lt;/P&gt;&lt;P&gt;&amp;amp;Auswertungstag.&amp;nbsp;= '01JAN2021'D =&amp;gt; &amp;amp;Monat. = 12 and &amp;amp;Jahr1.=2020&lt;/P&gt;&lt;P&gt;&amp;amp;Auswertungstag.&amp;nbsp;= '01DEC2020'D =&amp;gt; &amp;amp;Monat. = 11 and &amp;amp;Jahr1.=2020&lt;/P&gt;&lt;P&gt;&amp;amp;Auswertungstag.&amp;nbsp;= '01FEB2021'D =&amp;gt; &amp;amp;Monat. = 1 and &amp;amp;Jahr1.=2021&lt;/P&gt;&lt;P&gt;I tried:&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Auswertungstag = &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%sysevalf&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;('01OCT2020'd); &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008000"&gt;*Bei Bedarf: Datum vorgeben;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Spanne=9; &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008000"&gt;*Spanne: Anzahl der Monate des Dashboardszeitraum;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*Der Monatszeitraum fängt an, mit dem Vormonat von dem Auswertungstag;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%if&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(month(&amp;amp;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;Auswertungstag.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;)) ne &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%then&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Monat=&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(month(&amp;amp;Auswertungstag.));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%else&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Monat=12;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;Monat ne &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;12&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%then&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Jahr1= &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(year(&amp;amp;Auswertungstag.)); &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%else&lt;/FONT&gt; &lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Jahr1= &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%sysfunc&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(year(&amp;amp;Auswertungstag.)-1);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; Jahr2= &lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%eval&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;Jahr1.-1);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;=Auswertungstag.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;=Spanne.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;=Monat.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;=Jahr1.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;%put&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;=Jahr2.;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;and I got the Errors:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;ERROR: The %IF statement is not valid in open code.&lt;/P&gt;&lt;P&gt;ERROR: The %ELSE statement is not valid in open code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you help to correct this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 13:19:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/correction-of-macrocode-needed/m-p/692512#M24909</guid>
      <dc:creator>PierreYvesILY</dc:creator>
      <dc:date>2020-10-19T13:19:08Z</dc:date>
    </item>
    <item>
      <title>Re: correction of macrocode needed</title>
      <link>https://communities.sas.com/t5/New-SAS-User/correction-of-macrocode-needed/m-p/692515#M24911</link>
      <description>&lt;P&gt;hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thank you for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the results of the Code:&lt;/P&gt;&lt;P&gt;930 %let Auswertungstag = '01OCT2020'D; *Bei Bedarf: Datum vorgeben;&lt;/P&gt;&lt;P&gt;931 %let Spanne=9; *Spanne: Anzahl der Monate des Dashboardszeitraum;&lt;/P&gt;&lt;P&gt;932 *Der Monatszeitraum fängt an, mit dem Vormonat von dem Auswertungstag;&lt;/P&gt;&lt;P&gt;933 %let Monat= %eval(%month(&amp;amp;Auswertungstag.));&lt;/P&gt;&lt;P&gt;934 %let Jahr1= %eval(%year(&amp;amp;Auswertungstag.));&lt;/P&gt;&lt;P&gt;935 %let Jahr2= %eval(&amp;amp;Jahr1.-1);&lt;/P&gt;&lt;P&gt;936 %put NOTE: &amp;amp;=Auswertungstag.;&lt;/P&gt;&lt;P&gt;NOTE: AUSWERTUNGSTAG='01OCT2020'D&lt;/P&gt;&lt;P&gt;937 %put NOTE: &amp;amp;=Spanne. &amp;amp;=Monat. &amp;amp;=Jahr1. &amp;amp;=Jahr2.;&lt;/P&gt;&lt;P&gt;10 The SAS System 14:47 Monday, October 19, 2020&lt;/P&gt;&lt;P&gt;NOTE: SPANNE=9 MONAT=10 JAHR1=2020 JAHR2=2019&lt;/P&gt;&lt;P&gt;938 %put NOTE: Subnmitted from &amp;amp;_CLIENTAPP version &amp;amp;_CLIENTVERSION;&lt;/P&gt;&lt;P&gt;NOTE: Subnmitted from 'SAS Enterprise Guide' version '7.100.5.6214'&lt;/P&gt;&lt;P&gt;939 %put NOTE- Running on SAS version &amp;amp;sysvlong;&lt;/P&gt;&lt;P&gt;Running on SAS version 9.03.01M2P081512&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 13:23:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/correction-of-macrocode-needed/m-p/692515#M24911</guid>
      <dc:creator>PierreYvesILY</dc:creator>
      <dc:date>2020-10-19T13:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: correction of macrocode needed</title>
      <link>https://communities.sas.com/t5/New-SAS-User/correction-of-macrocode-needed/m-p/692518#M24913</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/281554"&gt;@PierreYvesILY&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;hello Paige,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm a SAS new user, and I don't know much about macrocode.&lt;/P&gt;
&lt;P&gt;%superq and&amp;nbsp;%qsysfunc are functions I don't know at all.&lt;/P&gt;
&lt;P&gt;Finally, what I Need is :&lt;/P&gt;
&lt;P&gt;1. a macro Monat where the month as a 'number' is saved : for instance: January =1 and December = 12.&lt;/P&gt;
&lt;P&gt;The &amp;amp;Monat. has to be the month BEFORE the &amp;amp;Auswertungstag.&lt;/P&gt;
&lt;P&gt;therefore:&amp;nbsp;if &amp;amp;Auswertungstag.&amp;nbsp;= '01JAN2021'D =&amp;gt; &amp;amp;Monat. = 12&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;So, this is not the original problem. It really helps if you state the actual problem in your original message, rather than changing it after we have worked on your problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
%let Auswertungstag = %sysevalf('01JAN2020'd); *Bei Bedarf: Datum vorgeben;
%let previous_month = %sysfunc(intnx(month,&amp;amp;Auswertungstag,-1,b));
%let year=%sysfunc(year(&amp;amp;previous_month));
%let month=%sysfunc(month(&amp;amp;previous_month));

%put &amp;amp;=Auswertungstag;
%put &amp;amp;=previous_month;
%put &amp;amp;=year;
%put &amp;amp;=month;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;An important point here, whenever you deal with calendar dates is to represent the data as a valid SAS date, which means the number of days since January 1, 1960. So, January 1, 2020 is represented as 21915. Then you can find the previous month using the INTNX function, so you don't have to write your own code that knows what month comes before any specified month, SAS has already created a function to do this.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Oct 2020 13:37:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/correction-of-macrocode-needed/m-p/692518#M24913</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-19T13:37:18Z</dc:date>
    </item>
  </channel>
</rss>

