Desktop productivity for business analysts and programmers

If Statements useing a macro variable created in a Macro

Reply
Established User
Posts: 1

If Statements useing a macro variable created in a Macro

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

Super User
Posts: 24,003

Re: If Statements useing a macro variable created in a Macro

Posted in reply to carlosnreis

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.

 

 

Super User
Posts: 6,933

Re: If Statements useing a macro variable created in a Macro

Posted in reply to carlosnreis

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;

Ask a Question
Discussion stats
  • 2 replies
  • 143 views
  • 0 likes
  • 3 in conversation