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

Hello, I have a problem with  the ODS output not working when it is coded inside a SAS macro code in SAS EG 8.3. The same SAS code works perfectly in SAS EG 7.1 Also if the ODS statement is coded outside a macro code it also works in SAS EG 8.3. But I need it to be working when it is coded inside a macro code.  How I can fix that problem?  Is there any options I can use before running my macro code or a special setup/options I should check in SAS EG 8.3 to fix the problem with the ODS? Any tips/ help will be very much appreciated. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

ODS fails because somehow it gets turned off, or because somehow the macro code isn't creating the desired SAS (non-macro) code. Beyond that, I'd be guessing.

 

You really haven't even told us what is in the log, such as errors. Are there any? What about warnings? What about data sets that are supposed to have some observations but wind up with 0 observations, according to the log?

You can try running the command

 

options mprint;

 

and then running your macro again, this will provide more useful information in the log.

--
Paige Miller

View solution in original post

15 REPLIES 15
Quentin
Super User

Please share a small example of code that causes the problem.   Please share the log from running that code. Also please explain the problem.  Do you get errors in your log?  Is the ODS output file not being created? etc.  

The Boston Area SAS Users Group is hosting free webinars!

Register now at https://www.basug.org/events.
LLOUKINE
Obsidian | Level 7

unfortunately I cannot copy and paste my code here as it is inside a virtual machine which is is subject for the vetting process by someone else if I want to get it outside of a VM. But the problem is that the output file with the summary stats from proc surveyfreq is not being generated if that is coded withing a macro code. If the same proc surveyfreq run is coded w/o a macro i can generate that output file. 

 

Quentin
Super User

Without code or a log we would be pretty much guessing at possibilities.

 

To start, would turn on system option MPRINT, and review your log for the PROC SURVEYFREQ step to make sure it completed successfully, that the input data did not have 0 obs, etc.

 

There shouldn't be anything special about running a PROC inside a macro.  And shouldn't be a difference between the EG versions.  So it's hard for me to guess what might be happening.

 

The Boston Area SAS Users Group is hosting free webinars!

Register now at https://www.basug.org/events.
LLOUKINE
Obsidian | Level 7

thanks for the suggestion. I will try it tomorrow. 

 

PaigeMiller
Diamond | Level 26

ODS fails because somehow it gets turned off, or because somehow the macro code isn't creating the desired SAS (non-macro) code. Beyond that, I'd be guessing.

 

You really haven't even told us what is in the log, such as errors. Are there any? What about warnings? What about data sets that are supposed to have some observations but wind up with 0 observations, according to the log?

You can try running the command

 

options mprint;

 

and then running your macro again, this will provide more useful information in the log.

--
Paige Miller
LLOUKINE
Obsidian | Level 7

Thank you again for your suggestion to use mprint option. It helped me to identify a problem. It turned out that if I have a comment in front of my ods statement inside  the macro code coded as  * Comment...;  then my ods statement pick up that "*" somehow and not  working. In the log I see MPRINT (FREQTABLES) : * ods select X;  When I changed the syntax for my comments to  /* Comment x */  then my ods worked.  It seems that if I want to leave a  comments in my sas macro I must use /* Comment xx*/ syntax. Problem solved! thanks! 

PaigeMiller
Diamond | Level 26

Hello @LLOUKINE 

Please mark my post in this thread correct, and unmark your reply correct.

--
Paige Miller
Tom
Super User Tom
Super User

SAS has three types of comments.

 

Normal comment statements. 

* comment ;

These are treated by the macro processor the same as any other normal statement.  They would not actually cause any trouble in your macro is used properly.  I suspect that the real issue was a missing semicolon.

 

Macro comment statements

%* comment ;

These will be treated by macro processor as macro statements that do nothing.

 

Block comments.

/* comment that can contain ; characters */

You cannot nest these.  Any attempt to do so will cause trouble. Example:

/* This is commented out
  /* And this is also */
  But this it not  and now SAS or macro processor
  is going to look for a semicolon to end this strange "but" statement
*/

 

 

LLOUKINE
Obsidian | Level 7

thank you for the summary! I will keep this in mind.  If I missed a semi column my macro would not work at all but it worked and I got the results as a sas report. The only problem I had is that I could not control the ods output. I experimented with the commenting syntax and if I used /* ...*/ the problem disappeared. When I changed it back to *...;  the ODS statement did not work and in the log I saw *ods..;  Mystery. But thanks. I will use 'block comments from now one. 

Tom
Super User Tom
Super User

Statement comments should work fine in macros. And they are very valuable in making your SAS log more readable when using the MPRINT option since they will appear in the log.

 73         * statement comment ;
 74         data test; x=1; run;
 
 NOTE: The data set WORK.TEST has 1 observations and 1 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 75         
 76         %macro test;
 77         * statement comments work fine in macros ;
 78         data test; x=1; run;
 79         %mend test;
 80         options mprint;
 MPRINT(TEST):   * statement comments work fine in macros ;
 81         %test;
 MPRINT(TEST):   data test;
 MPRINT(TEST):   x=1;
 MPRINT(TEST):   run;
 
 NOTE: The data set WORK.TEST has 1 observations and 1 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       

There are two situations that I have seen that have caused trouble.

One is the use of unbalanced quotes inside the statement comment.  Those will work in open code. 

 73         * Don't use unbalanced quotes ;
 74         data test; x=1; run;
 
 NOTE: The data set WORK.TEST has 1 observations and 1 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 75  

But in a macro definition they can confuse the macro parser and cause your whole session so get confused and possibly required that it be restarted.

 

If the quotes are balanced over the whole macro definition they work, but don't depend on that.

 76         %macro test;
 77         * Don't use unbalanced quotes ;
 78         data test; x=1; run;
 79         * You won't like the results ;
 80         %mend test;
 81         options mprint;
 MPRINT(TEST):   * Don't use unbalanced quotes ;
 82         %test;
 MPRINT(TEST):  data test;
 MPRINT(TEST):   x=1;
 MPRINT(TEST):   run;
 
 NOTE: The data set WORK.TEST has 1 observations and 1 variables.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 MPRINT(TEST):  * You won't like the results ;

 

The other place I have seen them cause trouble is when using SAS/Connect session and remote submitting the macro definition to the remote session.  Something about the way the lines are parsed and transmitted to the remote sesssion to be compiled can cause it to get confused.   I have seen macros that fail, but that just adding a single space so that the lines parse slightly differently they work.

 

I have found it works better when the remote session defines the macro itself by using %INCLUDE or autocall libraries (impliect %INCLUDE).  That seems to avoid whatever was causing the confusion.

LLOUKINE
Obsidian | Level 7

thank you for your comments again. I will test your code in the virtual machine (VM) and see what happens. My new SAS EG (8.3) is installed withing a VM that we test now and we (not only me, my colleague as well) discovered that the macros that we used previously in SAS EG 5.3 that is installed on our laptops and worked perfect, now in the VM environment have problems with the ods. Perhaps your comment "The other place I have seen them cause trouble is when using SAS/Connect session and remote submitting the macro definition to the remote session.  Something about the way the lines are parsed and transmitted to the remote session to be compiled can cause it to get confused.   I have seen macros that fail, but that just adding a single space so that the lines parse slightly differently they work." is the answer to our problems.  I really appreciate all your comments as it helps me to understand what may be wrong and how we can adapt our coding if we are forced to use sas via a VM. 

Kathryn_SAS
SAS Employee

Just to add a little more context about macro and the recommended style to comments, here is a SAS Note from Technical Support:

KB0036213 

LLOUKINE
Obsidian | Level 7

thank you!

andreas_lds
Jade | Level 19

One of the interesting differences between EG 7.x and 8.x is the change of the default output type. In the earlier version it was SAS Report, beginning with 8.x it is html.

 

If you can't provide the code used, please provide at least some more information about what the code does.

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 15 replies
  • 2086 views
  • 7 likes
  • 6 in conversation