/* DATA step to create the SASUSER.CLASS data set            */

data sasuser.class(label='Student information');
   input name $ 1-8 sex $ 11 age height weight;
   label name  ='First name'
         sex   ='Gender'
         age   ='Age in years'
         height='Height in inches'
         weight='Weight in pounds';
datalines;
Alice     F 13 56.5  84.0
Becka     F 13 65.3  98.0
Gail      F 14 64.3  90.0
Karen     F 12 56.3  77.0
Kathy     F 12 59.8  84.5
Mary      F 15 66.5 112.0
Sandy     F 11 51.3  50.5
Sharon    F 15 62.5 112.5
Tammy     F 14 62.8 102.5
Alfred    M 14 69.0 112.5
Duke      M 14 63.5 102.5
Guido     M 15 67.0 133.0
James     M 12 57.3  83.0
Jeffrey   M 13 62.5  84.0
John      M 12 59.0  99.5
Philip    M 16 72.0 150.0
Robert    M 12 64.8 128.0
Thomas    M 11 57.5  85.0
William   M 15 66.5 112.0
run;

   /* Copyright(c) 1996 by SAS Institute Inc., Cary, NC USA     */

   /* Approach 1.                                               */

DFINIT:
   namelist=makelist();
   dsid=open('sasuser.class');
   nlevels=0;
   rc=lvarlevel(dsid,'name',nlevels,namelist);
   rc=close(dsid);
   return;

NAMESEL:
   index=popmenu(namelist);
   if index>0 then
      do;
         name=getitemc(namelist,index);
         call send(_self_,'_erroroff_column_','name');
      end;
   return;

NAME:
   if searchc(namelist,name)=0 then
      do;
         call send(_self_,'_erroron_column_','name');
         _msg_='NAME is invalid. Please reenter.';
         call send(_viewer_,'_goto_column_','name');
      end;
   else
      call send(_self_,'_erroroff_column_','name');
   return;

AGE:
   if age<10 then
      do;
         call send(_self_,'_erroron_column_','age');
         _msg_='AGE is invalid. Please reenter.';
         call send(_viewer_,'_goto_column_','age');
      end;
   else
      call send(_self_,'_erroroff_column_','age');
   return;

HEIGHT:
   if height<50 then
      do;
         call send(_self_,'_erroron_column_','height');
         _msg_='HEIGHT is invalid. Please reenter.';
         call send(_viewer_,'_goto_column_','height');
      end;
   else
      call send(_self_,'_erroroff_column_','height');
   return;

WEIGHT:
   if weight<50 then
      do;
         call send(_self_,'_erroron_column_','weight');
         _msg_='WEIGHT is invalid. Please reenter.';
         call send(_viewer_,'_goto_column_','weight');
      end;
   else
      call send(_self_,'_erroroff_column_','weight');
   return;

DFTERM:
   rc=dellist(namelist);
   return;

   /* Copyright(c) 1996 by SAS Institute Inc., Cary, NC USA     */

   /* Approach 2.                                               */

DFINIT:
   namelist=makelist();
   dsid=open('sasuser.class');
   nlevels=0;
   rc=lvarlevel(dsid,'name',nlevels,namelist);
   rc=close(dsid);
   control error;
   return;

NAMESEL:
   index=popmenu(namelist);
   if index>0 then
      do;
         name=getitemc(namelist,index);
         call send(_self_,'_erroroff_column_','name');
      end;
   return;

MAIN:
   if searchc(namelist,name)=0 then
      do;
         call send(_self_,'_erroron_column_','name');
         _msg_='NAME is invalid. Please reenter.';
         call send(_viewer_,'_goto_column_','name');
      end;
   else call send(_self_,'_erroroff_column_','name');

   if age<10 then
      do;
         call send(_self_,'_erroron_column_','age');
         _msg_='AGE is invalid. Please reenter.';
         call send(_viewer_,'_goto_column_','age');
      end;
   else
      call send(_self_,'_erroroff_column_','age');

   if height<50 then
      do;
         call send(_self_,'_erroron_column_','height');
         _msg_='HEIGHT is invalid. Please reenter.';
         call send(_viewer_,'_goto_column_','height');
      end;
   else
      call send(_self_,'_erroroff_column_','height');

   if weight<50 then
      do;
         call send(_self_,'_erroron_column_','weight');
         _msg_='WEIGHT is invalid. Please reenter.';
         call send(_viewer_,'_goto_column_','weight');
      end;
    else
       call send(_self_,'_erroroff_column_','weight');
    return;

DFTERM:
   rc=dellist(namelist);
   return;


   /* Copyright(c) 1995 by SAS Institute Inc., Cary, NC USA     */

   /* Approach 3.                                               */

length mod inerror $ 1;

DFINIT:
   namelist=makelist();
   dsid=open('sasuser.class');
   nlevels=0;
   rc=lvarlevel(dsid,'name',nlevels,namelist);
   rc=close(dsid);
   control error;
   return;

NAMESEL:
   index=popmenu(namelist);
   if index>0 then
      do;
         name=getitemc(namelist,index);
         call send(_self_,'_erroroff_column_','name');
      end;
   return;

MAIN:
      /* Check for NAME column                                  */

   call send(_self_,'_get_column_attribute_','name','modified',mod);
   call send(_self_,'_get_column_attribute_','name','error',inerror);

   if mod='Y' or inerror='Y' then
      do;
         if searchc(namelist,name)=0 then
            do;
               call send(_self_,'_erroron_column_','name');
               _msg_='Invalid value for NAME. Please reenter.';
               call send(_viewer_,'_goto_column_','name');
            end;
         else call send(_self_,'_erroroff_column_','name');
      end;

      /* Check for AGE column                                   */

   call send(_self_,'_get_column_attribute_','age','modified',mod);
   call send(_self_,'_get_column_attribute_','age','error',inerror);

   if mod='Y' or inerror='Y' then
      do;
         if age<10 then
            do;
               call send(_self_,'_erroron_column_','age');
               _msg_='AGE must be greater than 10. Please reenter.';
               call send(_viewer_,'_goto_column_','age');
            end;
          else call send(_self_,'_erroroff_column_','age');
      end;

   return;

DFTERM:
   rc=dellist(namelist);
   return;
 
   /* Copyright(c) 1996 by SAS Institute Inc., Cary, NC USA     */

   /* Approach 4.                                               */

length colname $ 8 _column_name_ $ 8;

DFINIT:
   namelist=makelist();
   dsid=open('sasuser.class');
   nlevels=0;
   rc=lvarlevel(dsid,'name',nlevels,namelist);
   rc=close(dsid);
   control error;
   errorlst=makelist();
   return;

NAMESEL:
   index=popmenu(namelist);
   if index>0 then
      do;
         name=getitemc(namelist,index);
         call send(_self_,'_erroroff_column_','name');
         position=searchc(errorlst,'NAME');
         if position>0 then
         errorlst=delitem(errorlst,position);
      end;
   return;

MAIN:
   if listlen(errorlst) then
      do;
         colname=getitemc(errorlst,listlen(errorlst));
         select(colname);
            when('NAME')
            _msg_='Invalid value for NAME. Please reenter.';
            when('AGE')
            _msg_='AGE must be greater than 10. Please reenter.';
            when('HEIGHT')
            _msg_='HEIGHT must be greater than 50. Please reenter.';
            when('WEIGHT')
            _msg_='WEIGHT must be greater than 50. Please reenter.';
         otherwise;
         end;
         call send(_viewer_,'_goto_column_',colname);
      end;
   return;

NAME:
AGE:
HEIGHT:
WEIGHT:
   errorflag=0;
   if _column_name_='NAME' then
      do;
         if searchc(namelist,name)=0 then errorflag=1;
      end;

   if _column_name_='AGE' then
      do;
         if AGE<10 then errorflag=1;
      end;

   if _column_name_='HEIGHT' then
      do;          
         if HEIGHT<50 then errorflag=1;
      end;

   if _column_name_='WEIGHT' then
      do;
         if WEIGHT<50 then errorflag=1;
      end;
   link updtlist;
   return;

UPDTLIST:
   position=searchc(errorlst,_column_name_);
      if errorflag=1 then
         do;
            if position le 0 then
               do;
                  call send(_self_,'_erroron_column_',_column_name_);
                  errorlst=insertc(errorlst,_column_name_);
               end;
         end;
   else
      if position>0 then
         do;
            call send(_self_,'_erroroff_column_',_column_name_);
            errorlst=delitem(errorlst,position);
         end;
   return;

DFTERM:
   rc=dellist(namelist);
   rc=dellist(errorlst);
   return;