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
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.)
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;
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.
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.)
%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
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.