Hi all,
I have a PROC PRINT, and the set of variables to be output is based on the value of a macro variable called tab (the print is outputting sheets to an Excel file). Basically, if tab starts with Shared_, a certain variable should be printed, but that variable should not be output for any tab that doesn't start with Shared_.
Previously, I set up something to output or not based on a specific tab name, and this worked perfectly:
PROC PRINT DATA=HAVE;
VAR V1 V2
%IF &TAB. = ABC %THEN %DO;
V3
%END;
V4 V5;
RUN;
IE, V3 would be print for the ABC tab and not any others.
However, now, instead of a specific tab name, I have tab characteristics which apply to multiple tabs (begins with shared_). I have tried setting it up similarly as above but using index, and then substr, but neither will work for me:
PROC PRINT DATA=HAVE;
VAR V1 V2
%IF %INDEX(&TAB., 'SHARED') > 0 %THEN %DO;
V3
%END;
V4 V5;
RUN;
PROC PRINT DATA=HAVE;
VAR V1 V2
%IF %SUBSTR(&TAB., 1, 7) = 'SHARED_' %THEN %DO;
V3
%END;
V4 V5;
RUN;
Any help is much appreciated.
Try eliminating the quotes in the %INDEX function. Example:
%IF %INDEX(&TAB., SHARED) > 0 %THEN %DO;
Also, eliminate the quotes around SHARED_
Macro variables don't need to be tested against strings that have quotes around them, in fact, it is almost always the wrong thing to do.
Never tell us it didn't work and provide no other details. From now on, when code doesn't work, we need to see the LOG, and if the output is wrong, then show us the output and explain why it is incorrect.
Try eliminating the quotes in the %INDEX function. Example:
%IF %INDEX(&TAB., SHARED) > 0 %THEN %DO;
Also, eliminate the quotes around SHARED_
Macro variables don't need to be tested against strings that have quotes around them, in fact, it is almost always the wrong thing to do.
Never tell us it didn't work and provide no other details. From now on, when code doesn't work, we need to see the LOG, and if the output is wrong, then show us the output and explain why it is incorrect.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.