DATA Step, Macro, Functions and more

halfnorm macro: proc genmod, ods output in a macro loop

Posts: 24

halfnorm macro: proc genmod, ods output in a macro loop

I am attempting to update my halfnorm macro for V9+, current version at

Visualizing Categorical Data: halfnorm - Half normal plot for generalized linear models

I'm having trouble with a section of the macro designed to run proc genmod repeatedly to get a simulated envelope

based on randomly generated values from a given distribution.  I would prefer to have no printed output generated,

but commented out the ODS LISTING statements for now. The essence is the following loop:

%put HALFNORM: Generating &nres simulated residual sets...;

%if %sysevalf(&sysver  >= 7) %then %do;

*    ods listing exclude all;


%do i=1 %to &nres;

options nonotes;

%*put Generating residual set &i;


ods output ObStats=work._hres&i(keep=&res rename=(&res=res&i));

proc genmod data=_obstat_;

   %if %length(&class)>0 %then %do; class &class; %end;

   %if %length(&freq)>0 %then %do;  freq &freq;   %end;

    %if %length(&trials)=0 %then %do;

       model _y&i         = &model /


    %else %do;

       model _y&i/&trials = &model /


    %if %length(&dist)>0 %then %do;  dist=&dist %end;

    %if %length(&link)>0 %then %do;  link=&link %end;

    %if %length(&offset)>0 %then %do; offset=&offset  %end;

    %if %length(&mopt)>0 %then %do;  %str(&mopt) %end;

        obstats residuals;

*  make 'obstats'  out=_hres&i(keep=&res rename=(&res=res&i));


%end;  /* End %do i */

I'm getting warnings, then errors regarding the ObStats datasets when I try to use them

HALFNORM: Generating 19 simulated residual sets...

MPRINT(HALFNORM):   * ods listing exclude all;

MPRINT(HALFNORM):   options nonotes;

MPRINT(HALFNORM):   ods output ObStats=work._hres1(keep=stresdev


MPRINT(HALFNORM):   proc genmod data=_obstat_;

MPRINT(HALFNORM):   class dept gender admit;

MPRINT(HALFNORM):   model _y1 = dept|gender|admit@2 / dist=POISSON obstats


MPRINT(HALFNORM):   * make 'obstats' out=_hres&i(keep=&res rename=(&res=res&i));


WARNING: Output 'ObStats' 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.


I attach the current version I'm testing, together with a log file from a test run.  Can anyone see what is wrong and how to correct it?

Test code:

title 'Berkeley Admissions data';

%include catdata(berkeley);

data berkeley;

    set berkeley;

   cell = trim(put(dept,dept.)) ||

          gender ||



%include macros(halfnorm12);

options mprint;

%halfnorm(data=berkeley, class="dept" gender admit,

    resp=freq, model=dept|gender|admit@2, dist=poisson, id=cell);

Super User
Posts: 10,473

Re: halfnorm macro: proc genmod, ods output in a macro loop

Is there a reason that the OUTPUT= option for creating dataset output isnt' acceptable?

The online help suggests these reasons for using this option:

  •   The OUTPUT statement produces no tabular output. 
  • The OUTPUT statement creates a SAS data set more efficiently than ODS. This can be an advantage for large data sets.

  • You can specify the individual statistics to be included in the SAS data set.

Posts: 24

Re: halfnorm macro: proc genmod, ods output in a macro loop

Thanks for the suggestion, but the

OUTPUT statement is not currently an option, at least not without a major re-write.

This may turn out to provide a good solution, but I'd rather see if I can tweak the ODS first.

The OUTPUT statement did not exist when the macro was originally written.  It provides similar output statistics

to what is available via ODS, but seems to have been constructed by an independent contractor, because the names

of the output variables differ in a bewildering way.



streschi          stdreschi

stresdev         stdresdev


Posts: 7,356

Re: halfnorm macro: proc genmod, ods output in a macro loop


I don't know if the attached fixes your problem, but it runs without error on 9.3.

I may have made some additional changes that I don't now remember, but the only significant ones I can recall are having changed your comments to /* */ type rather than the * type, and commenting out one additional statement, namely:

ods listing exclude none;



Super User
Posts: 9,671

Re: halfnorm macro: proc genmod, ods output in a macro loop

Or if you annony these information , you can redirect them into a txt file .

Like something :

proc printto log='c:\log.txt' ;run;


proc printto;run;

Ask a Question
Discussion stats
  • 4 replies
  • 4 in conversation