X-Mailer: Pegasus Mail v2.1c R5.
Newsgroups: bit.listserv.sas-l
Date:         Tue, 7 Apr 1992 17:54:57 EDT
Reply-To:     Ray Pass <PASSRAY@CPMAIL-NZ.CIS.COLUMBIA.EDU>
From:         Ray Pass <PASSRAY@CPMAIL-NZ.CIS.COLUMBIA.EDU>
Subject:      PROC REPORT and by-group processing

Here's a brand mew undocumented feature of my favorite SAS procedure, PROC
REPORT.  Seems that when you run PROC REPORT against a sorted dataset and use
a BY statement, the PROC isn't very well-behaved in terms of releasing memory
after each by-group is processed, as are other PROCs, and as it should be.
The memory usage just keeps mounting until there just ain't no more to use.
The PROC starts producing output for each by-group in sequence, and then just
quits with an error up in the JES2 JOB LOG which says:

    +viloada: autoload failed for module SASXFMT . Not enough memory.

This is the error I get when running batch in MVS with SAS 6.07.  I can't
speak for interactive processing or other platforms or other SAS versions.  I
confirmed the situation by increasing the memory I had to play with - I upped
both the region and the value on my MEMSIZE option.  When I did this, I got
the same error, but more output.  It just chugged a little further before
quitting.  I notified SI about this and they confirmed my suspicion.  This
may not effect you unless you're running the right data configuration, i.e.
unless you've got MANY by-groups (I had 140).

Until this gets fixed, you've got to use a work-around to gets things done.
It was actually a neat little exersize and I present my solution, looking for
improvements.  The task is to process individual by-groups in a dataset
without using a BY statement.  There's nothing here specific to PROC REPORT.
The method should work with any procedure.  I did make use of a powerful new
6.07 feature, MODIFY, which allows you to modify datasets in place, but this
part of the process could have been done with alternative methods.

The whole thing is contained in the REPBY macro.  The real data is in the
permanent SAS dataset OUT.REAL.  The byvar contained in this dataset is BYVAR.
The steps are:

        1) create a temp dataset TEMPBY containing 1 variable, BYVAR, with
           one obs per BYVAR value

        2) create a macrovar, MACBY, which holds the current value of BYVAR

        3) use MODIFY (and REMOVE) to remove the current obs from the TEMPBY
           dataset

        4) set up a LASTREC macrovar to denote when the last obs from
           TEMPBY is being processed

        5) stop the current processing of the DATA TEMPBY step

        6) run the PROC REPORT on those obs from the permanent dataset
           for which BYVAR equals the current value of the macrovar MACBY

        7) after REPORT finishes, test the value of the macrovar LASTREC

        8) if the obs being processed is not the last one, i.e. its not
           the last BYVAR, cycle back and get another BYVAR and start
           another PROC REPORT

        9) after the last obs is processed, the REPBY macro finishes.

 *====================================================================;
 %MACRO REPBY;

  DATA TEMPBY;
     SET OUT.REAL(KEEP=BYVAR);
     BY BYVAR;
     IF FIRST.BYVAR;
 *------------------------------------------------------;
  %NEXT:
  DATA TEMPBY;
     SET TEMPBY;
     CALL SYMPUT('MACBY',BYVAR);
     MODIFY TEMPBY END=LASTREC;
     CALL SYMPUT('LASTREC',PUT(LASTREC,1.));
     REMOVE;
     STOP;
  RUN;
 *------------------------------------------------------;
  PROC REPORT DATA=OUT.REAL(WHERE=(BYVAR="&MACBY"));


            ((( PROC REPORT CODE GOES HERE )))


  %IF &LASTREC NE 1 %THEN %GOTO NEXT;

  RUN;

 %MEND REPBY;
 *=======================================================================;

Have fun!

Ray


 *--------------------------------------------------------------------------*
 | Ray Pass, Ph.D.                                    Voice: (212) 305-7748 |
 | Columbia-Presbyterian Medical Center                 Fax: (212) 305-3302 |
 | 161 Ft. Washington Ave.       AP1310                                     |
 | New York, NY 10032-3784               passray@cpmail-nz.cis.columbia.edu |
 *--------------------------------------------------------------------------*
Comments: Gated by NETNEWS@AUVM.AMERICAN.EDU