BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Walternate
Obsidian | Level 7

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. 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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.


@Walternate 

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.

--
Paige Miller

View solution in original post

1 REPLY 1
PaigeMiller
Diamond | Level 26

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.


@Walternate 

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.

--
Paige Miller

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 1 reply
  • 761 views
  • 0 likes
  • 2 in conversation