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

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)

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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

6 REPLIES 6
Reeza
Super User

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;

 

osi814
Obsidian | Level 7

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.

Reeza
Super User

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)
osi814
Obsidian | Level 7

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 🙂

Rick_SAS
SAS Super FREQ

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.

osi814
Obsidian | Level 7

Thank you Rick for your reply and explanation!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 6 replies
  • 2642 views
  • 2 likes
  • 3 in conversation