The SAS Output Delivery System and reporting techniques

Evaluating Math Expressions with Macros

Reply
Regular Contributor
Posts: 228

Evaluating Math Expressions with Macros

I understand that macro variables are text values, so it has a hard time with things like:

%if &var. < 5 %then %do...

when &var. = 1.3 (since the decimal is considered a character and therefore not evaluable).

I have a line of code that I cannot get past because of this issue.  Here is what I have:

%if compute&j. = min(of compute1-compute&maxvisit.) %then %do;

I have even tried putting the expression in a %sysevalf() function to see if that would help--no go:

%if %sysevalf(compute&j. = min(of compute1-compute&maxvisit.)) %then %do;

Does anyone know how I can work around this?  If you need more code from me, let me know.

Super User
Posts: 11,134

Re: Evaluating Math Expressions with Macros

If you use a function such as MIN generally then you want %sysfunc for macro calculations.

It looks like your are attempting to use data set variable names in the MIN is that the case? If so then you probably shouldn't be using %if as the macro comparison won't have the values of the dataset variables. The macro is resolved at compile not datastep execution.

I would recommend posting the enough code to see how you are using this %IF. If inside a data step then the entire data step may be needed.

Regular Contributor
Posts: 228

Re: Evaluating Math Expressions with Macros

I am doing this in PROC REPORT.  I wanted to use the CALL DEFINE statement to highlight cells if the cell was the minimum value of the other cells in that row.  You did give me an idea that helped.  In the data step that creates the input data for PROC REPORT, I just defined a new variable called MINCOMPUTE, then I was able to change my %IF statement in PROC REPORT to read:

%if %sysevalf(compute&j. = mincompute) %then %do;

That seems to have fixed the error I was receiving, but I still can't get the highlighting to work.  That might be another post soon if I can't figure that part out.

SAS Super FREQ
Posts: 8,820

Re: Evaluating Math Expressions with Macros

Hi:

  Just remember 2 things about highlighting:

1) if you are using ACROSS items, you have to use absolute column numbers in the CALL DEFINE for the highlighting

call define('_c4_','style','style={...}');

and

2) if you are highlighting, you must remember that PROC REPORT does *NOT* have a PDV. So you can only highlight what's been placed on the report row. For example:

column name age var1 var2 var3;

In a COMPUTE block for AGE (for example) you cannot "touch" VAR1, VAR2 or VAR3 with a CALL DEFINE statement. That's because when PROC REPORT is dealing with AGE, it has not yet put those vars on the report row yet.

cynthia

Ask a Question
Discussion stats
  • 3 replies
  • 419 views
  • 3 likes
  • 3 in conversation