DATA Step, Macro, Functions and more

Issue with macro parameter expression containing .

Reply
Contributor
Posts: 36

Issue with macro parameter expression containing .

Hello,
I would like to make the following macro call :
%PrintProbleme(&TableContraintes, org, %SUPERQ(org eq 0 or org eq .), "Rejet1 : org=0", 1);

I have trouble withe the parameter : org eq 0 or org eq .

I have tried the %Bquote, %Str and %Nrbquote functions too.

There is a problem with the point.
How could I submit the parameter : org eq 0 or org eq .
correctly ?

Thank you.

Phil
Valued Guide
Posts: 2,177

Re: Issue with macro parameter expression containing .

> %PrintProbleme(&TableContraintes, org, %SUPERQ(org eq
> 0 or org eq .), "Rejet1 : org=0", 1);
>
> I have trouble withe the parameter : org eq 0 or org
> eq .

I won't argue about the wisdom of using a macro here, but just point out
1 in sql[pre] org eq 0 or org is null [/pre]may perform better
2 in data step[pre] (if org) [/pre] selects non-missing and non-zero data
3 in macro language superq() expects a macro variable (, or macro name) as the parameter, and not plain syntax [pre] %str( org eq 0 or org = . ) [/pre] might provide adequate protection for that dot. An alternative providing slightly stronger protection than %str() is %quote().
Error handling of the failing parameter will (probably) be complicated by the internals of your macro %PrintProbleme.
Since this simple use without macro protection of your filter syntax [pre] %let BC =
org eq 0 or org = .
;[/pre] works just fine outside a macro... see this log[pre]51 %let BC =
52 org eq 0 or org = .
53 ;
54 DATA ;
55 INPUT ORG REP$ ;
56 LIST;CARDS;

RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----
57 1 REP1
58 2 report2
59 . empty
60 0 return-code-OK
NOTE: The data set WORK.DATA4 has 4 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


61 ;
62 option symbolgen mlogic mprint ;
63 data cases;
64 set ;
SYMBOLGEN: Macro variable BC resolves to org eq 0 or org = .
65 if &bc ;
66 run;

NOTE: There were 4 observations read from the data set WORK.DATA4.
NOTE: The data set WORK.CASES has 2 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds[/pre]
I'm assuming the problem you get is caused by the handling of the parameter, rather than that dot in the value of the parameter.

Good Luck
PeterC
Contributor
Posts: 36

Re: Issue with macro parameter expression containing .

Thank you Peter.

I have modified the PrintProbleme macro removing the %str calls :

%Macro PrintProbleme(MyTableIn, MyVar, MyCondition, MyTitle3, MyAffichePasSiZero) / store;
%LOCAL Nb;
%Let Nb=0;

/* Calcul nombre d'enregistrements */
Proc Sql noprint; SELECT Count(1) INTO :Nb FROM &MyTableIn WHERE &MyCondition; Quit;

%IF (%Eval(&Nb)>0) OR (%Eval(&MyAffichePasSiZero) ne 1) %Then %Do;
%Title3Pdf(%STR(&MyTitle3 : &Nb. Enregistrements));

DATA temp;
SET &MyTableIn;
Obs = _N_;
%LabelsVarsNatives();
Run;

Proc Print DATA=temp label style(TABLE)={width=1000};
Id Obs / style=[just=center color=black fontsize=8PT];
Var org noagent statut contrat &MyVar / style=[just=center color=black fontsize=8PT];
/* ajouter style(column)={width=200} pour modifier largeur colonne à la mano */
WHERE &MyCondition;
Run;

Proc DELETE DATA=temp; Run;
%End;
%Mend;

And it works.

The (if org) clause is very interesting, equivalent to org ne 0 and org ne .

Thanks.

phil
Valued Guide
Posts: 2,177

Re: Issue with macro parameter expression containing .

weird

> %IF (%Eval(&Nb)>0) OR (%Eval(&MyAffichePasSiZero) ne

why does it need these %EVAL() calls
Contributor
Posts: 36

Re: Issue with macro parameter expression containing .

Hi,
to evaluate the value of &Nb and &MyAffichePasSiZero.

It is not necessary ?

Phil
Valued Guide
Posts: 2,177

Re: Issue with macro parameter expression containing .

On reading macro doc in the past (iirc) I have seen statements like "%if implicitly performs a %eval".
Unless you have introduced the complexity of macro quoting (which defers resolving a macro expression), a reference to a macro variable will be resolved/evaluated when found by the macro compiler.
This points at one way that might require these %eval() - where the macro variable referred like [pre] %eval(&macroVariable) [/pre] contains text that might confuse the %if logical expression. However, I think that might cause the %eval() to fail anyway. If such contents in a macro variable might need the isolation of its evaluation that %eval() provides then the parentheses, without %eval, would be sufficient, like [pre] %if (&Nb)>0 OR (&MyAffichePasSiZero) ne 1 %then [/pre]
So, what kind of values might be found in &Nb and &MyAffichePasSiZero?

PeterC
Contributor
Posts: 36

Re: Issue with macro parameter expression containing .

Thanks,
Only numeric integer values can be found for both &Nb and &MyAffichePasSiZero.

Phil.
Valued Guide
Posts: 2,177

Re: Issue with macro parameter expression containing .

then they do'nt need to be wrapped with %eval()
Contributor
Posts: 36

Re: Issue with macro parameter expression containing .

Okay thanks Peter.
Ask a Question
Discussion stats
  • 8 replies
  • 405 views
  • 0 likes
  • 2 in conversation