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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.