- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.)
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%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