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;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.