BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
reehfarias
Calcite | Level 5
%LET M1 = MES1;
%LET M2 = MES2;
%LET M3 = MES3;

%LET ATUAL = MES1;

%IF &ATUAL. = &M2. OR &ATUAL. = &M3. %THEN %DO;
/*CODIGO*/
%END;

Escrevi uma estrutura assim, porém o SAS está entrando no código da condição, quando na verdade não era pra entrar, pois a variável "atual" não é igual a M2 e nem M3.

Estou desconfiando que ele não reconhece o OR na linha de condição. Não sei por que não está funcionando, parece ser muito simples.

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

Using %IF-%THEN-%ELSE in SAS programs in open code has its limitations like no nesting. 

 

Patrick_0-1696888652426.png

 

For your sample code

%LET ANOMES1 = mes1;
%LET ANOMES2 = mes2;
%LET ANOMES3 = mes3;

%LET M_ATUAL = mes1;
%macro doit();
%IF &M_ATUAL. = &ANOMES2. OR &M_ATUAL. = &ANOMES3. %THEN %DO;
	%IF &M_ATUAL.=&ANOMES2. %THEN %DO;
		/*sub code*/
	%END;
        /*REST OF THE CODE*/
%END;
%mend;
%doit();

 

 

View solution in original post

3 REPLIES 3
Patrick
Opal | Level 21

The code you shared does what you expected. You must have gotten something wrong with your testing.

%LET M1 = MES1;
%LET M2 = MES2;
%LET M3 = MES3;

/* FALSE */
%LET ATUAL = MES1;
%IF &ATUAL. = &M2. OR &ATUAL. = &M3. %THEN
  %DO;
    data _null_;
      put "Condition True";
    run;
  %END;
%else
  %do;
    data _null_;
      put "Condition False";
    run;
  %end;

/* TRUE */
%LET ATUAL = MES3;
%IF &ATUAL. = &M2. OR &ATUAL. = &M3. %THEN
  %DO;
    data _null_;
      put "Condition True";
    run;
  %END;
%else
  %do;
    data _null_;
      put "Condition False";
    run;
  %end;

 

Patrick_0-1696640171347.png

 

reehfarias
Calcite | Level 5

I think the problem is that I put another %if inside my %if, because when I commented it, the code worked (did nothing as it was supposed to)

Is there anything wrong with this structure?

%LET ANOMES1 = mes1;
%LET ANOMES2 = mes2;
%LET ANOMES3 = mes3;

%LET M_ATUAL = mes1;
%IF &M_ATUAL. = &ANOMES2. OR &M_ATUAL. = &ANOMES3. %THEN %DO;
	%IF &M_ATUAL.=&ANOMES2. %THEN %DO;
		/*sub code*/
	%END;
        /*REST OF THE CODE*/
%END;
Patrick
Opal | Level 21

Using %IF-%THEN-%ELSE in SAS programs in open code has its limitations like no nesting. 

 

Patrick_0-1696888652426.png

 

For your sample code

%LET ANOMES1 = mes1;
%LET ANOMES2 = mes2;
%LET ANOMES3 = mes3;

%LET M_ATUAL = mes1;
%macro doit();
%IF &M_ATUAL. = &ANOMES2. OR &M_ATUAL. = &ANOMES3. %THEN %DO;
	%IF &M_ATUAL.=&ANOMES2. %THEN %DO;
		/*sub code*/
	%END;
        /*REST OF THE CODE*/
%END;
%mend;
%doit();

 

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 760 views
  • 1 like
  • 2 in conversation