The SAS Output Delivery System and reporting techniques

Problem wrapping Proc GLM in a macro (using ODS output)

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

Problem wrapping Proc GLM in a macro (using ODS output)

[ Edited ]

Hello,

 

I am trying to report the anova results from PROC GLM in a dataset using ODS. If I use only one variable (p_total_a, looking to see if it differs across 13 different ID groups), what I am trying to do works perfectly (code below):

ods trace on / label;

ods output modelanova=output;

proc glm data=dataset;

class id;

model p_total_a = id;

lsmeans id;

run;

ods output close;

ods trace off;

 

However, I have multiple variables that I need to do this for, so I tried to wrap the procedure in a Macro, but it only creates one output dataset instead of multiple (only for the first variable I run through the macro). If I check the log, after the first iteration of the macro with the first variable, I get a warning message that reads:

WARNING: Output 'modelanova' was not created. Make sure that the output object name, label, or path is spelled correctly. Also,

verify that the appropriate procedure options are used to produce the requested output object. For example, verify that the NOPRINT option is not used.

WARNING: The current ODS SELECT/EXCLUDE/OUTPUT statement was cleared because the end of a procedure step was detected. Probable causes for this include the non-termination of an interactive procedure (type quit; to end the procedure) and a run group with no output.

 

Below is the code I am using for the macro. Any suggestions welcome. Thank you!

ods trace on / label;

%macro macro(var=);

ods output modelanova=output_&var;

proc glm data=dataset;

class id;

model &var = id;

lsmeans id;

run;

ods output close;

%mend macro;

ods trace off;

%macro(var=p_total_a)

%macro(var=p_total_b)

 

 


Accepted Solutions
Solution
‎01-06-2016 01:44 PM
Super User
Posts: 19,770

Re: Problem wrapping Proc GLM in a macro (using ODS output)

I tried running your code - it generated errors, macro name for one. Fixing those and moving ods table inside seemed to generate results. I can't recall at the moment what the ODS OUTPUT statement does, but I think closing it caused issues. I don't think it does what your thinking as well...

 

This works for me, good luck:

 

%macro repeat_glm(var=);

proc glm data=sashelp.class;
class sex;
model &var = sex;
lsmeans sex;
ods table modelanova=output_&var;
run;
ods trace off;
%mend repeat_glm;

%repeat_glm(var=age)
%repeat_glm(var=weight)

View solution in original post


All Replies
Super User
Posts: 19,770

Re: Problem wrapping Proc GLM in a macro (using ODS output)

[ Edited ]

Move

ods output close;

to outside your macro. You close it on the first iteration, so your destination is no longer open for any output.

 

EDIT:

 

ods trace on / label;
%macro macro(var=);
ods output modelanova=output_&var;
proc glm data=dataset;
class id;
model &var = id;
lsmeans id;
run;

%mend macro;
ods trace off;
%macro(var=p_total_a)
%macro(var=p_total_b)

ods output close;

 

Contributor
Posts: 20

Re: Problem wrapping Proc GLM in a macro (using ODS output)

Thank you for your suggestion and reply! I just tried running your edited program, but I got the same warning message and it still only produced one output dataset for the first variable.

Solution
‎01-06-2016 01:44 PM
Super User
Posts: 19,770

Re: Problem wrapping Proc GLM in a macro (using ODS output)

I tried running your code - it generated errors, macro name for one. Fixing those and moving ods table inside seemed to generate results. I can't recall at the moment what the ODS OUTPUT statement does, but I think closing it caused issues. I don't think it does what your thinking as well...

 

This works for me, good luck:

 

%macro repeat_glm(var=);

proc glm data=sashelp.class;
class sex;
model &var = sex;
lsmeans sex;
ods table modelanova=output_&var;
run;
ods trace off;
%mend repeat_glm;

%repeat_glm(var=age)
%repeat_glm(var=weight)
Contributor
Posts: 20

Re: Problem wrapping Proc GLM in a macro (using ODS output)

Thank you so much Reeza! That worked for my program. I had made up that macro name for this forum so it was easier to read but guess that wasn't the best idea Smiley Happy

SAS Super FREQ
Posts: 3,752

Re: Problem wrapping Proc GLM in a macro (using ODS output)

You do not need to use ODS OUTPUT CLOSE at all. PROC GLM is an interactive procedure, so it does not write certain files or create certain output until the procedure exits.  Change to RUN statement to a QUIT statement and you should get all the output without having to CLOSE the ODS destination.

Contributor
Posts: 20

Re: Problem wrapping Proc GLM in a macro (using ODS output)

Thank you Rick for your reply and explanation!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 793 views
  • 1 like
  • 3 in conversation