Hello,
my Code:
%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(&Auswertungstag.));
%let Jahr1= %eval(%year(&Auswertungstag.));
%let Jahr2= %eval(&Jahr1.-1);
%put &Auswertungstag.;
%put &Spanne.;
%put &Monat.;
%put &Jahr1.;
%put &Jahr2.;
I get following Errors in the log:
GOPTIONS ACCESSIBLE;
27 %let Auswertungstag = '01OCT2020'D;
28 %let Spanne=9;
29
30 %let Monat= %eval(%month(&Auswertungstag.));
31 %let Jahr1= %eval(%year(&Auswertungstag.));
NOTE: The quoted string currently being processed has become more than 262 bytes long. You might have unbalanced quotation marks.
32 %let Jahr2= %eval(&Jahr1.-1);
33 %put &Auswertungstag.;
34 %put &Spanne.;
35 %put &Monat.;
36 %put &Jahr1.;
37 %put &Jahr2.;
Why is there no result in the log after the %put Statement?
it seems it doesn't calculate anything.
How can I correct this?
@PierreYvesILY wrote:
hello Paige,
I'm a SAS new user, and I don't know much about macrocode.
%superq and %qsysfunc are functions I don't know at all.
Finally, what I Need is :
1. a macro Monat where the month as a 'number' is saved : for instance: January =1 and December = 12.
The &Monat. has to be the month BEFORE the &Auswertungstag.
therefore: if &Auswertungstag. = '01JAN2021'D => &Monat. = 12
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.
Try this:
%let Auswertungstag = %sysevalf('01JAN2020'd); *Bei Bedarf: Datum vorgeben;
%let previous_month = %sysfunc(intnx(month,&Auswertungstag,-1,b));
%let year=%sysfunc(year(&previous_month));
%let month=%sysfunc(month(&previous_month));
%put &=Auswertungstag;
%put &=previous_month;
%put &=year;
%put &=month;
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.
I get different errors in the LOG when I run this exact code.
There is no such thing as a %MONTH or %YEAR macro function.
But this works, keeping in mind Maxim 28 which says you should not format macro variables (so &Auswertungstag is not formatted)
%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(&Auswertungstag.));
%let Jahr1= %sysfunc(year(&Auswertungstag.));
%let Jahr2= %eval(&Jahr1.-1);
%put &=Auswertungstag.;
%put &=Spanne.;
%put &=Monat.;
%put &=Jahr1.;
%put &=Jahr2.;
hallo Paige,
I've got the following error messages ; is it possible, that it is due to SAS 9.3?
43 %let Auswertungstag = %sysevalf('01OCT2020'd); *Bei Bedarf: Datum vorgeben;
ERROR: Open code statement recursion detected.
44 %let Spanne=9; *Spanne: Anzahl der Monate des Dashboardszeitraum;
ERROR: Open code statement recursion detected.
45 *Der Monatszeitraum fängt an, mit dem Vormonat von dem Auswertungstag;
46 %let Monat= %sysfunc(month(&Auswertungstag.));
ERROR: Open code statement recursion detected.
47 %let Jahr1= %sysfunc(year(&Auswertungstag.));
ERROR: Open code statement recursion detected.
2 The SAS System 13:41 Monday, October 19, 2020
48 %let Jahr2= %eval(&Jahr1.-1);
ERROR: Open code statement recursion detected.
49 %put &=Auswertungstag.;
ERROR: Open code statement recursion detected.
50 %put &=Spanne.;
ERROR: Open code statement recursion detected.
51 %put &=Monat.;
ERROR: Open code statement recursion detected.
52 %put &=Jahr1.;
ERROR: Open code statement recursion detected.
53 %put &=Jahr2.;
ERROR: Open code statement recursion detected.
54
55 GOPTIONS NOACCESSIBLE;
56 %LET _CLIENTTASKLABEL=;
ERROR: Open code statement recursion detected.
57 %LET _CLIENTPROCESSFLOWNAME=;
ERROR: Open code statement recursion detected.
58 %LET _CLIENTPROJECTPATH=;
ERROR: Open code statement recursion detected.
59 %LET _CLIENTPROJECTPATHHOST=;
ERROR: Open code statement recursion detected.
60 %LET _CLIENTPROJECTNAME=;
ERROR: Open code statement recursion detected.
61 %LET _SASPROGRAMFILE=;
ERROR: Open code statement recursion detected.
62 %LET _SASPROGRAMFILEHOST=;
ERROR: Open code statement recursion detected.
63
What happens if you close SAS, and then re-start it and run the code I showed?
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:
%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(&Auswertungstag.));
%let Jahr1= %eval(%year(&Auswertungstag.));
%let Jahr2= %eval(&Jahr1.-1);
%put NOTE: &=Auswertungstag.;
%put NOTE: &=Spanne. &=Monat. &=Jahr1. &=Jahr2.;
%put NOTE: Subnmitted from &_CLIENTAPP version &_CLIENTVERSION;
%put NOTE- Running on SAS version &sysvlong;
This code runs without error or warnings for me from Enterprise Guide 8.2 running SAS 9.4M7.
The last two lines should provide your Enterprise Guide and SAS version information, which might be helpful if further troubleshooting is necessary.
The code work properly without %superq and without %eval and with %sysfunc instead of %qsysfunc
hello Paige,
I'm a SAS new user, and I don't know much about macrocode.
%superq and %qsysfunc are functions I don't know at all.
Finally, what I Need is :
1. a macro Monat where the month as a 'number' is saved : for instance: January =1 and December = 12.
The &Monat. has to be the month BEFORE the &Auswertungstag.
therefore: if &Auswertungstag. = '01JAN2021'D => &Monat. = 12
2. a macro Jahr1 where the year of that given monat is stored.
&Auswertungstag. = '01JAN2021'D => &Monat. = 12 and &Jahr1.=2020
&Auswertungstag. = '01DEC2020'D => &Monat. = 11 and &Jahr1.=2020
&Auswertungstag. = '01FEB2021'D => &Monat. = 1 and &Jahr1.=2021
I tried:
%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;
%if %sysfunc(month(&Auswertungstag.)) ne 0 %then %let Monat=%sysfunc(month(&Auswertungstag.));
%else %let Monat=12;
%if &Monat ne 12 %then %let Jahr1= %sysfunc(year(&Auswertungstag.));
%else %let Jahr1= %sysfunc(year(&Auswertungstag.)-1);
%let Jahr2= %eval(&Jahr1.-1);
%put &=Auswertungstag.;
%put &=Spanne.;
%put &=Monat.;
%put &=Jahr1.;
%put &=Jahr2.;
and I got the Errors:
ERROR: The %IF statement is not valid in open code.
ERROR: The %ELSE statement is not valid in open code.
Could you help to correct this?
Thanks for your help
@PierreYvesILY wrote:
hello Paige,
I'm a SAS new user, and I don't know much about macrocode.
%superq and %qsysfunc are functions I don't know at all.
Finally, what I Need is :
1. a macro Monat where the month as a 'number' is saved : for instance: January =1 and December = 12.
The &Monat. has to be the month BEFORE the &Auswertungstag.
therefore: if &Auswertungstag. = '01JAN2021'D => &Monat. = 12
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.
Try this:
%let Auswertungstag = %sysevalf('01JAN2020'd); *Bei Bedarf: Datum vorgeben;
%let previous_month = %sysfunc(intnx(month,&Auswertungstag,-1,b));
%let year=%sysfunc(year(&previous_month));
%let month=%sysfunc(month(&previous_month));
%put &=Auswertungstag;
%put &=previous_month;
%put &=year;
%put &=month;
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.
hello,
thank you for your help.
the results of the Code:
930 %let Auswertungstag = '01OCT2020'D; *Bei Bedarf: Datum vorgeben;
931 %let Spanne=9; *Spanne: Anzahl der Monate des Dashboardszeitraum;
932 *Der Monatszeitraum fängt an, mit dem Vormonat von dem Auswertungstag;
933 %let Monat= %eval(%month(&Auswertungstag.));
934 %let Jahr1= %eval(%year(&Auswertungstag.));
935 %let Jahr2= %eval(&Jahr1.-1);
936 %put NOTE: &=Auswertungstag.;
NOTE: AUSWERTUNGSTAG='01OCT2020'D
937 %put NOTE: &=Spanne. &=Monat. &=Jahr1. &=Jahr2.;
10 The SAS System 14:47 Monday, October 19, 2020
NOTE: SPANNE=9 MONAT=10 JAHR1=2020 JAHR2=2019
938 %put NOTE: Subnmitted from &_CLIENTAPP version &_CLIENTVERSION;
NOTE: Subnmitted from 'SAS Enterprise Guide' version '7.100.5.6214'
939 %put NOTE- Running on SAS version &sysvlong;
Running on SAS version 9.03.01M2P081512
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.