/**********************************************************************/


INIT: 
   control enter;
   dsid=open('sasuser.fitness');
   if (dsid=0) then
      do;
         put 'ERROR: Unable to open data set';
         _status_='H';
         return;
      end;

   call set(dsid);
return;


/**********************************************************************/


TABLEGET:
      rc=fetchobs(dsid,_currow_);

         /* check for end of data set or                   */
         /* other errors (rc is positive                   */
         /* for errors, negative for warnings)             */
      if ((rc=%sysrc(_SWEOF)) or (rc>0)) then
         do;
            call notify('table','_endtable_');
            if (rc^=%sysrc(_SWEOF)) then
               _msg_=sysmsg();
            return;
         end;

return;


/**********************************************************************/


      rc=filename('myprint',
                            /* physical-filename */
                                                   );
      if (rc) then
         do;
            _msg_=sysmsg();
            put _msg_;
            _status_='H';
            return;
         end;


/**********************************************************************/


MAIN: 
   cmd=word(1,'u');
   if (cmd='PRINT') then
      do;

            /* drain the PRINT command                     */
         call nextcmd();

            /* open the file in OUTPUT mode                */
            /* (this clears the file)                      */
         fid=fopen('myprint','o');
         if (fid=0) then
            do;
               _msg_='ERROR: Unable to open file';
               return;
            end;

               /* set the mode to PRINT and start          */
               /* printing with row 1                      */
            mode='PRINT';
            row=1;

            link printit;

               /* close the output file                    */
            rc=fclose(fid);
            if (rc) then
               do;
                  _msg_=sysmsg();
                  return;
               end;

            end;

return;


/**********************************************************************/


PRINTIT:
         /* get the current toprow (used                   */
         /* later to restore the table)                    */
      call notify('table','_get_toprow_',toprow);

         /* get the number of rows visible                 */
      call notify('table','_get_visrow_',visrow);

         /* loop and print until the table                 */
         /* says to stop                                   */
      do while (mode='PRINT');
         call notify('table','_set_toprow_',row);
         call notify('table','_refresh_');
         row=row+visrow;
      end;

         /* restore the previous toprow                    */
      call notify('table','_set_toprow_',toprow);

return;


/**********************************************************************/


      if (mode='PRINT') then
         do;
            rc=fput(fid,'Age: ');
            rc=fput(fid,age);

            rc=fput(fid,'  Weight: ');
            rc=fput(fid,weight);

            rc=fput(fid,'  Resting pulse: ');
            rc=fput(fid,rstpulse);

            rc=fput(fid,'  Running pulse: ');
            rc=fput(fid,runpulse);

            rc=fwrite(fid);

            return;
         end;


/**********************************************************************/


      /* check for end of data set or                      */
      /* other errors (rc is positive                      */
      /* for errors, negative for warnings)                */
   if ((rc=%sysrc(_SWEOF)) or (rc>0)) then
      do;
         call notify('table','_endtable_');
         mode='';
         if (rc^=%sysrc(_SWEOF)) then
            _msg_=sysmsg();
         return;
      end;


/**********************************************************************/


INIT: 
   control enter;
   dsid=open('sasuser.fitness');
   if (dsid=0) then
      do;
         put 'ERROR: Unable to open data set';
         _status_='H';
         return;
      end;

   call set(dsid);
   
   rc=filename('myprint',
                         /* physical-filename */
                                                ');
   if (rc) then
      do;
         _msg_=sysmsg();
         put _msg_;
         _status_='H';
         return;
      end;

return;

MAIN: 
   cmd=word(1,'u');
      if (cmd='PRINT') then
         do;

               /* drain the PRINT command                  */
            call nextcmd();

               /* open the file in OUTPUT mode             */
               /* (this clears the file)                   */
            fid=fopen('myprint','o');
            if (fid=0) then
               do;
                  _msg_='ERROR: Unable to open file';
                  return;
               end;

               /* set the mode to PRINT and start          */
               /* printing with row 1                      */
            mode='PRINT';
            row=1;

            link printit;

               /* close the output file                    */
            rc=fclose(fid);
            if (rc) then
               do;
                  _msg_=sysmsg();
                  return;
               end;

            end;

return;

PRINTIT:
         /* get the current toprow (used                   */
         /* later to restore the table)                    */
      call notify('table','_get_toprow_',toprow);

         /* get the number of rows visible                 */
      call notify('table','_get_visrow_',visrow);

         /* loop and print until the table                 */
         /* says to stop                                   */
      do while (mode='PRINT');
         call notify('table','_set_toprow_',row);
         call notify('table','_refresh_');
         row=row+visrow;
      end;

         /* restore the previous toprow                    */
      call notify('table','_set_toprow_',toprow);

return;

TABLEGET:
      rc=fetchobs(dsid,_currow_);

         /* check for end of data set or                   */
         /* other errors (rc is positive                   */
         /* for errors, negative for warnings)             */
      if ((rc=%sysrc(_SWEOF)) or (rc>0)) then
         do;
            call notify('table','_endtable_');
            mode='';
            if (rc^= %sysrc(_SWEOF)) then
               _msg_=sysmsg();
            return;
         end;

      if (mode='PRINT') then
         do;
            rc=fput(fid,'Age: ');
            rc=fput(fid, age);

            rc=fput(fid,'  Weight: ');
            rc=fput(fid,weight);

            rc=fput(fid,'  Resting pulse: ');
            rc=fput(fid,rstpulse);

            rc=fput(fid,'  Running pulse: ');
            rc=fput(fid,runpulse);

            rc=fwrite(fid);

            return;
         end;

return;


/**********************************************************************/


PRINTIT:
         /* get the current toprow (used                   */
         /* later to restore the table)                    */
      call notify('table','_get_toprow_',toprow);

         /* get the number of rows visible                 */
      call notify('table','_get_visrow_',visrow);

         /* get the max number of rows                     */
      call notify('table','_get_maxrow_',maxrow);

         /* loop and print until the table                 */
         /* says to stop                                   */
      do while (row0)) then
         do;
            call endtable();
            mode='';
            if (rc^=%sysrc(_SWEOF)) then
               _msg_=sysmsg();
            return;
         end;

      if (mode='PRINT') then
         do;

            if (mode2='VISROW') then
               visrow=_currow_;

            rc=fput(fid,'Age: ');
            rc=fput(fid,age);

            rc=fput(fid,'  Weight: ');
            rc=fput(fid,weight);

            rc=fput(fid,'  Resting pulse: ');
            rc=fput(fid,rstpulse);

            rc=fput(fid,'  Running pulse: ');
            rc=fput(fid,runpulse);

            rc=fwrite(fid);

            return;
         end;

return;


/**********************************************************************/