BookmarkSubscribeRSS Feed
djbateman
Lapis Lazuli | Level 10

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.

3 REPLIES 3
ballardw
Super User

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.

djbateman
Lapis Lazuli | Level 10

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.

Cynthia_sas
SAS Super FREQ

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

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!

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
  • 3 replies
  • 1007 views
  • 3 likes
  • 3 in conversation