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


libname invty '
                 /* SAS-data-library */
                                          ';
                                          
data invty.stock;                         
   modify invty.stock;                    
   recdate=today();                       
run;                                      


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


data invty.stock;            
   modify invty.stock addinv;
   by partno;                
   instock=instock+nwstock;  
   recdate=today();          
run;                         


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


instock=instock+nwstock;


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


instock=nwstock;


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


data invty.stock;            
   modify invty.stock addinv;
   by partno;                
run;                         


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


data invty.stock;                    
   set newp;                         
   modify invty.stock point=tool_obs;
   price=newprice;                   
   recdate=today();
run;               


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


data invty.stock;                                            
   set newp;                                                 
   modify invty.stock point=tool_obs nobs=max_obs;           
   if _error_=1 then do;                                     
      put 'ERROR occurred for TOOL_OBS= ' tool_obs /         
          'during DATA step iteration ' _n_ /                
          'TOOL_OBS value may be out of range for data set.';
      _error_=0;                                             
      stop;                                                  
   end;                                                      
   price=newprice;                                           
   recdate=today();                                          
run;                                                         


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


data invty.stock;                
   set addinv;                   
   modify invty.stock key=partno;
   instock=instock+nwstock;      
   recdate=today();              
run;                             


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


/*  Example 1: No OUTPUT, REMOVE, or REPLACE Statements Are Specified */

data a b;                                                            
   modify b;                                                         

   /* Include here additional DATA step code that modifies the data   */
   /* in B and generates the data to be written to new or replacement */
   /* data set A                                                      */
                                                          
run;                                                      

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


/*  Example 2: REMOVE Statement Is Specified Explicitly               */

data a b;                                                     
   modify b;                                                  
                                                              
      /* Additional code to change data in B                          */             
                                                              
   if 
        /* some condition */
                               then                            
      remove b;                                               
run;                                                          


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


/*  Example 3: OUTPUT and REPLACE Statements Are Specified Explicitly */

data a b;                                                 
   modify b;                                              
                                                          
      /* Change data in data set B                                    */

   if 
        /* some condition */
                               then                            
      remove b;                                                                              

   else if              
             /* some other condition */
                                          then      
      output a;                                           
   else replace b;                                        
run;                                                      


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


data invty.stock;                                            
   set receive;                                              
   modify invty.stock key=partno;                            
   select (_iorc_);                                          
      when (%sysrc(_sok)) do;  /* Match located,           */
                               /* rewrite obs.             */
                                                             
             /* Code to change some data in STOCK          */        
                                                             
         replace;                                            
      end;                                                   
      when (%sysrc(_dsenom)) do;  /* No match, append obs. */
         output;                                             
         _error_=0;                                          
      end;                                                   
      otherwise do;    /* An unexpected I/O condition      */
                                                             
             /* Code to print error message                */              
                                                             
         _error_=0;                                          
         stop;                                               
      end;                                                   
   end;                                                      
run;                                                         


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


data a;               
   if 0 then modify a;
   set b;             
   output;            
run;                  


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


data a;    /* A contains two numeric variables, X and Y */
   infile 'external.data.file';                           
   input field1 field2;                                   
   modify a;                                              
   x=field1;                                              
   y=field2;                                              
run;                                                      


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

   /* A has only one variable, X */
data a;   
   modify a;                              
   y=x;                                   
run;                                      


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


   /* A has only one variable, Y, and one observation */ 
data a;                                                  
   modify a;                                             
   y='new value';                                        
   output;                                               
run;


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


if _n_ eq 10 then stop;


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


data a; 
   x=1; 
   str1='text 1'; 
run;              
                  
data b;           
   x=1;           
   str2='text 2'; 
run;              
                  
data a;           
   modify a b;    
   by x;          
   str1=str2;     
run;              
                  
proc print;       
run;              


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