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)
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)
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;
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.
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)
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 🙂
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.
Thank you Rick for your reply and explanation!
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: