BookmarkSubscribeRSS Feed
carlosnreis
Calcite | Level 5

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

2 REPLIES 2
Reeza
Super User

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.

 

 

Astounding
PROC Star

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 629 views
  • 0 likes
  • 3 in conversation