%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.
Using %IF-%THEN-%ELSE in SAS programs in open code has its limitations like no nesting.
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();
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;
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;
Using %IF-%THEN-%ELSE in SAS programs in open code has its limitations like no nesting.
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();
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Lock in the best rate now before the price increases on April 1.
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.
Ready to level-up your skills? Choose your own adventure.