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 dear SAS experts,

 

I have this Code:

%let Auswertungstag = '01JAN2021'D; *Bei Bedarf: Datum vorgeben;

%let Spanne=12; *Spanne: Anzahl der Monate des Dashboardszeitraum;

*Der Monatszeitraum fängt an, mit dem Vormonat von dem Auswertungstag;

%let KUM_param=0;

%if &KUM_param=0 %then %let KUM_Steuer = &Spanne.; %else %let KUM_Steuer = 33;

%put &Auswertungstag.;

%put &Spanne. &KUM_param. &KUM_Steuer.;

 

which leads to the following errors:

 

GOPTIONS ACCESSIBLE;

26 %let Auswertungstag = '01JAN2021'D; *Bei Bedarf: Datum vorgeben;

27 %let Spanne=12; *Spanne: Anzahl der Monate des Dashboardszeitraum;

28 *Der Monatszeitraum fängt an, mit dem Vormonat von dem Auswertungstag;

29 %let KUM_param=0;

30 %if &KUM_param=0 %then %let KUM_Steuer = &Spanne.; %else %let KUM_Steuer = 33;

ERROR: The %IF statement is not valid in open code.

ERROR: The %ELSE statement is not valid in open Code.

 

what should I write?

thank you

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @PierreYvesILY,

 

You can avoid the difficulties of using %IF/%THEN in open code by using the IFN function:

%let KUM_Steuer = %sysfunc(ifn(&KUM_param=0, &Spanne, 33));

(This assumes that the last two arguments are numeric.)

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

You have to use %DO and %END in open code

 

%if &KUM_param=0 %then %do; %let KUM_Steuer = &Spanne.; %end;
%else %do; %let KUM_Steuer = 33; %end;

  

--
Paige Miller
PierreYvesILY
Pyrite | Level 9

hello Paige,

with the Code:

%let KUM_param=1; * Hier für Monatsdashboard 0 eingeben - fürs kumuliertes Dashboard 1 eingeben ;

%if &KUM_param=0 %then %do; %let KUM_Steuer = &Spanne.; %end;

%else %do; %let KUM_Steuer = 33; %end;

 

I've got the following error:

 

%let KUM_param=1; * Hier für Monatsdashboard 0 eingeben - fürs kumuliertes Dashboard 1 eingeben ;

40 %if &KUM_param=0 %then %do; %let KUM_Steuer = &Spanne.; %end;

ERROR: The %IF statement is not valid in open code.

ERROR: The %END statement is not valid in open code.

41 %else %do; %let KUM_Steuer = 33; %end;

ERROR: The %ELSE statement is not valid in open code.

ERROR: The %END statement is not valid in open Code.

FreelanceReinh
Jade | Level 19

Hello @PierreYvesILY,

 

You can avoid the difficulties of using %IF/%THEN in open code by using the IFN function:

%let KUM_Steuer = %sysfunc(ifn(&KUM_param=0, &Spanne, 33));

(This assumes that the last two arguments are numeric.)

Reeza
Super User

%IF/%THEN is only valid in open code in SAS 9.4TSM5+

It means you need to use a different SAS function (IFN) or wrap it in macro code.

 

https://blogs.sas.com/content/sasdummy/2018/07/05/if-then-else-sas-programs/

 


@PierreYvesILY wrote:

hello dear SAS experts,

 

I have this Code:

%let Auswertungstag = '01JAN2021'D; *Bei Bedarf: Datum vorgeben;

%let Spanne=12; *Spanne: Anzahl der Monate des Dashboardszeitraum;

*Der Monatszeitraum fängt an, mit dem Vormonat von dem Auswertungstag;

%let KUM_param=0;

%if &KUM_param=0 %then %let KUM_Steuer = &Spanne.; %else %let KUM_Steuer = 33;

%put &Auswertungstag.;

%put &Spanne. &KUM_param. &KUM_Steuer.;

 

which leads to the following errors:

 

GOPTIONS ACCESSIBLE;

26 %let Auswertungstag = '01JAN2021'D; *Bei Bedarf: Datum vorgeben;

27 %let Spanne=12; *Spanne: Anzahl der Monate des Dashboardszeitraum;

28 *Der Monatszeitraum fängt an, mit dem Vormonat von dem Auswertungstag;

29 %let KUM_param=0;

30 %if &KUM_param=0 %then %let KUM_Steuer = &Spanne.; %else %let KUM_Steuer = 33;

ERROR: The %IF statement is not valid in open code.

ERROR: The %ELSE statement is not valid in open Code.

 

what should I write?

thank you


 

 

SAS Innovate 2025: Register Now

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!

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
  • 4 replies
  • 662 views
  • 2 likes
  • 4 in conversation