BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PierreYvesILY
Pyrite | Level 9

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?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller

View solution in original post

8 REPLIES 8
PaigeMiller
Diamond | Level 26

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.;

 

 

--
Paige Miller
PierreYvesILY
Pyrite | Level 9

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

PaigeMiller
Diamond | Level 26

What happens if you close SAS, and then re-start it and run the code I showed?

--
Paige Miller
SASJedi
SAS Super FREQ

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. 

 

 

Check out my Jedi SAS Tricks for SAS Users
PaigeMiller
Diamond | Level 26
  • Why do you need %superq here?
  • Why do you need %qsysfunc instead of %sysfunc? (Month and year values should not require any macro quoting)
  • Why do you need %eval(%month(&Auswertungstag.)) instead of %month(&Auswertungstag.)?

The code work properly without %superq and without %eval and with %sysfunc instead of %qsysfunc

--
Paige Miller
PierreYvesILY
Pyrite | Level 9

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

 

 

PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
PierreYvesILY
Pyrite | Level 9

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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 8 replies
  • 775 views
  • 5 likes
  • 3 in conversation