Hi,
i have a problem in this code... the "IF" statement dont work... someone can help me?
The Macro Variable G_STATUS is created in this Macro
%macro CONSULTAR_TABELA(RELATORIO,BASE);
%GLOBAL G_STATUS;
%LOCAL STATUS;
proc sql;
SELECT T1.status INTO: STATUS
FROM CONTROLE.BASE_VALIDADOR T1
WHERE COMPRESS(RELATORIO) EQ &RELATORIO. AND COMPRESS(TABELA) EQ &BASE.
;
RUN;
%LET G_STATUS = &STATUS;
%mend CONSULTAR_TABELA;
and i would like to use this macro variable in this "IF" conditional:
data _NULL_;
%let RELATORIO = 'SOL';
%let TABELA = 'ZCRM_O02';
%CONSULTAR_TABELA(&RELATORIO,&TABELA);
%IF &g_status ="EM ATUALIZACAO" %then
x=1;
run;
The error is:
61 %IF &g_status ="EM ATUALIZACAO" %then
ERROR: The %IF statement is not valid in open code.
62 x=1;
63 run;
thanks for all
Well, the error is correct, macro logic is only good within a macro.
What are you trying to do? Yes, your code doesn't work, but without knowing what you're tyring to accomplish we can't offer a solution.
A couple of things to fix ...
First, your macro runs PROC SQL. You don't do that in the middle of a DATA step. So switch the order:
%let RELATORIO = 'SOL';
%let TABELA = 'ZCRM_O02';
%CONSULTAR_TABELA(&RELATORIO,&TABELA);
data _null_;
Next, even though %IF / %THEN is illegal, you don't really need it. You have started a DATA step, which uses IF / THEN (not %IF / %THEN). So you could use:
data _null_;
IF "&g_status" ="EM ATUALIZACAO" then x=1;
run;
If you merely want to examine the value of &G_STATUS instead of running a DATA step, you could simply use:
%put &G_STATUS;
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.
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.