BookmarkSubscribeRSS Feed
phil27
Calcite | Level 5
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
8 REPLIES 8
Peter_C
Rhodochrosite | Level 12
> %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
phil27
Calcite | Level 5
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
Peter_C
Rhodochrosite | Level 12
weird

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

why does it need these %EVAL() calls
phil27
Calcite | Level 5
Hi,
to evaluate the value of &Nb and &MyAffichePasSiZero.

It is not necessary ?

Phil
Peter_C
Rhodochrosite | Level 12
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
phil27
Calcite | Level 5
Thanks,
Only numeric integer values can be found for both &Nb and &MyAffichePasSiZero.

Phil.
Peter_C
Rhodochrosite | Level 12
then they do'nt need to be wrapped with %eval()
phil27
Calcite | Level 5
Okay thanks Peter.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 8 replies
  • 1296 views
  • 0 likes
  • 2 in conversation