New SAS User

Completely new to SAS or trying something new with SAS? Post here for help getting started.
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.

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-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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