data invty.stock;
    modify invty.stock;
    recdate=today();
 run; 

 data master;
       modify master;
       if mod='u' then x=1;
    run;

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

 data master;
 input ssn : $11. nickname $;
 datalines;
 134-56-9094 Megan
 160-58-1223 Kathryn
 161-60-5881 Joshua
 ;
 data trans;
 input ssn : $11. nickname $;
 datalines;
 134-56-9094 Meg
 142-67-9888 Bill
 160-58-1223 Kate
 161-60-5881 .
;
 data master;
       update master trans updatemode=nomissingcheck;
       by ssn;
    run;

 data master;
 input ssn : $11. nickname $;
 datalines;
 134-56-9094 Megan
 160-58-1223 Kathryn
 161-60-5881 Joshua
 ;
 data trans;
 input ssn : $11. nickname $;
 datalines;
 134-56-9094 Meg
 142-67-9888 Bill
 160-58-1223 Kate
 161-60-5881 .
;
 data master;
       modify master trans updatemode=nomissingcheck;
       by ssn;
    run;

 data master;
 input ssn : $11. nickname $;
 datalines;
 134-56-9094 Megan
 160-58-1223 Kathryn
 161-60-5881 Joshua
 ;
 data trans;
 input ssn : $11. nickname $;
 datalines;
 134-56-9094 Meg
 142-67-9888 Bill
 160-58-1223 Kate
 161-60-5881 .
;
 data master;
       modify master trans updatemode=nomissingcheck;
       by ssn;
       if _iorc_=0 then replace;
    run;

 data master;
 input ssn : $11. nickname $;
 datalines;
 134-56-9094 Megan
 160-58-1223 Kathryn
 161-60-5881 Joshua
 ;
 data trans;
 input ssn : $11. nickname $;
 datalines;
 134-56-9094 Meg
 142-67-9888 Bill
 160-58-1223 Kate
 161-60-5881 .
;
 data master;
       modify master trans updatemode=nomissingcheck;
       by ssn;
       if _iorc_=0 then replace;
       else _error_=0;
    run;

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

 data invty.stock;
    set addinv;
    modify invty.stock key=partno;
    if _iorc_=0 then do;      
      instock=instock+nwstock;
      recdate=today();
      replace;
    end;
    else _error_=0;
 run;  
 options source2;
    %include sasautos(sysrc);
    run;


 data master;
 input ssn : $11. nickname $;
 datalines;
 134-56-9094 Megan
 160-58-1223 Kathryn
 161-60-5881 Joshua
 ;
 data trans;
 input ssn : $11. nickname $;
 datalines;
 134-56-9094 Meg
 142-67-9888 Bill
 160-58-1223 Kate
 161-60-5881 .
;
 data master;                      
       modify master trans updatemode=nomissingcheck;                   
 by ssn;                         
       if _iorc_=%sysrc(_sok) then replace;   
       else _error_ =0; 
    run;
 
 data master;
 input ssn : $11. nickname $;
 datalines;
 134-56-9094 Megan
 160-58-1223 Kathryn
 161-60-5881 Joshua
 ;
 data trans;
 input ssn : $11. nickname $;
 datalines;
 134-56-9094 Meg
 142-67-9888 Bill
 160-58-1223 Kate
 161-60-5881 .
;
 data master;
       set trans;
       modify master key=ssn;
       i+1;
       if _iorc_=%sysrc(_sok) then do;
          set trans point=i;
          replace;
       end;
       else _error_=0;
    run;
 data master(index=(ssn));      
 input ssn : $11. nickname $;
 datalines;                      
 161-60-5881 Joshua             
 160-58-1223 Kathryn           
 134-56-9094 Megan              
;
 data trans;                
 input ssn : $11. nickname $;
 datalines;                     
 161-60-5881 Josh           
 160-58-1223 Kate           
 134-56-9094 Meg            
 142-67-9888 Bill
;
 data master;                             
       set trans(rename=(nickname=tnicknam));
       modify master key=ssn;                   
       if _iorc_=%sysrc(_sok) then do;
          nickname=tnicknam;   
          replace;
       end;   
       else _error_ = 0;   
    run;

 data combine;
   set lookup;
   set primary key=partno;
   select(_iorc_);
      when (%sysrc(_sok)) do;
         output;
      end;
      when (%sysrc(_dsenom)) do;
         _error_ = 0;
       end;
       otherwise;
    end;
 run;

 data master(index=(ssn));
 input ssn : $11. nickname $;  
 datalines;                     
 161-60-5881 Joshua            
 160-58-1223 Kathryn           
 134-56-9094 Megan             
        ;

        data trans;                   
 input ssn : $11. tnicknam $;  
 datalines;                      161-60-5881 Josh              
 160-58-1223 Kathy 
 134-56-9094 Meg               
 142-67-9888 Bill 
 160-58-1223 Kate 
        ;

 data master;
 set trans;
 modify master key=ssn;
 if _iorc_=%sysrc(_sok) then do;
    nickname=tnicknam;
    replace;
 end;
 else_error_=0;
run;

 data master(index=(ssn));
 input ssn : $11. nickname $;  
 datalines;                     161-60-5881 Joshua            
 160-58-1223 Kathryn           
 134-56-9094 Megan             
        ;

 data trans;                   
 input ssn : $11. tnicknam $;  
 datalines;                     
 161-60-5881 Josh              
 160-58-1223 Kathy 
 160-58-1223 Kate
 134-56-9094 Meg               
 142-67-9888 Bill 
        ;

 data master;
 set trans;
 modify master key=ssn;
 if _iorc_=%sysrc(_sok) then do;
    nickname=tnicknam;
    replace;
 end;
 else_error_=0;
run;

 proc print data=master;
    run;
 
 data master(index=(ssn));
 input ssn : $11. Nickname $;  
 datalines;                      
 161-60-5881 Joshua            
 160-58-1223 Kathryn           
 134-56-9094 Megan             
;
 data trans;                   
 input ssn : $11. tnicknam $;  
 datalines;                     
 161-60-5881 Josh              
 160-58-1223 Kathy 
 160-58-1223 Kate              
 134-56-9094 Meg               
 142-67-9888 Bill             
;
 data master;                             
 set trans;        
 modify master key=ssn/unique;                         
 select (_iorc_);                             
    when (%sysrc(_sok)) do;                   
       nickname=tnicknam;
       replace master;
    end;                                      
    when (%sysrc(_dsenom)) do;                
       _error_=0;                            
    end;                   
    otherwise;             
 end;                      
 
 proc print data=master;    
 run; 

 data master(index=(ssn));    
 input ssn : $11. nickname $; 
 datalines;                     
 161-60-5881 Joshua            
 161-60-5881 Joshua            
 160-58-1223 Kathryn           
 134-56-9094 Megan             
;
 data trans;                   
 input ssn : $11. nickname $;  
 datalines;                     
 161-60-5881 Josh              
 160-58-1223 Kathy             
 134-56-9094 Meg               
 142-67-9888 Bill             
;
 data master;                             
    set trans(rename=(nickname=tnicknam));       
    modify master key=ssn;                         
    select (_iorc_);                             
       when (%sysrc(_sok)) do;                   
           nickname=tnicknam;                    
           replace master;                         
       end;                                      
       when (%sysrc(_dsenom)) do;                
           _error_=0;                            
        end;                   
       otherwise;             
     end;                      
 
    proc print data=master;    
    run;

 data master(index=(ssn));    
 input ssn : $11. nickname $; 
 datalines;                      
 161-60-5881 Joshua           
 161-60-5881 Joshua            
 160-58-1223 Kathryn           
 134-56-9094 Megan             
;
 data trans;                   
 input ssn : $11. tnicknam $;  
 datalines;                     
 161-60-5881 Josh              
 160-58-1223 Kathy            
 134-56-9094 Meg               
 142-67-9888 Bill             
;
 data master;                              
 set trans;        
 do until (_iorc_=%sysrc(_dsenom));            
    modify master key=ssn;                       
    select (_iorc_);                           
       when (%sysrc(_sok)) do;                 
          nickname=tnicknam;                  
          replace master;                       
       end;                                    
 
       when (%sysrc(_dsenom)) do;
          _error_=0;         
       end;                   
       otherwise;             
    end;                      
 end; 
     
 proc print data=master;        
 run;                         

 data master(index=(ssn));
 input ssn : $11. nickname $;
 datalines;
 161-60-5881 Joshua
 161-60-5881 Joshua
 160-58-1223 Kathryn
 160-58-1223 Kathryn
 134-56-9094 Megan
;
 data trans;
 input ssn : $11. tnicknam $;
 datalines;
 161-60-5881 Josh
 160-58-1223 Kathy
 160-58-1223 Kate
 134-56-9094 Meg
 142-67-9888 Bill
;
 proc sort data=trans;
    by ssn;
 
 data master;
 set trans;
 by ssn;
 dummy=0;
 do until (_iorc_=%sysrc(_dsenom));
 if dummy then ssn='999-99-9999';
 modify master key=ssn;
    select (_iorc_);
       when (%sysrc(_sok)) do;
          nickname=tnicknam;
          replace master;
       end;
       when (%sysrc(_dsenom)) do;
          _error=0;
          if not last.ssn and not dummy then do;
             dummy=1;
             _iorc_=0;
             end;
          end;
          otherwise;
       end;
     end;

 proc print data=master;
 run;
 
 
 data lookup;
 input partno $ quantity;
 datalines;
 A066 8
 A220 2
 A812 10
 ;
 data primary(index=(partno));
 input partno $ desc $;
 datalines;
 A021 motor
 A033 bolt
 A043 nut
 A055 radiator
 A066 hose
 A066 hose2
 A066 hose3
 A078 knob
 A220 switch
 A223 bridge
;
 data combine;   
    set lookup;   
    do until(_iorc_=%sysrc(_dsenom));
    set primary key=partno;
    select(_iorc_);
       when (%sysrc(_sok)) do;
          output;
       end;
       when (%sysrc(_dsenom)) do;
          _error_=0;
       end;
       otherwise;
    end;
 end;
 
 proc print data=combine;
 run;

 data lookup;
 input partno $ district;
 datalines;
 A066 1
 A066 2
 A220 2
 A812 10
;
 data primary(index=(partno));
 input partno $ desc $;
 datalines;
 A021 motor
 A033 bolt
 A043 nut
 A055 radiator
 A066 hose
 A066 hose2
 A066 hose3
 A078 knob
 A220 switch
 223 bridge
;
 proc sql;
 create table shiplst as
 select a.*, b.desc
 from lookup as a, primary as b
 where a.partno=b.partno;
 quit;
 
 proc print data=shiplst;
 run;

 data lookup;
 input partno $ quantity;
 datalines;
 A066 8
 A220 2
 A812 10
 ;
 data primary(index=(partno));
 input partno $ desc $;
 datalines;
 A021 motor
 A033 bolt
 A043 nut
 A055 radiator
 A066 hose
 A078 knob
 A220 switch
 A223 bridge
;
 data combine;
 set lookup;
 set primary key=partno;
 select(_iorc_);
    when (%sysrc(_sok)) do; 
       output;
    end;
    when (%sysrc(_dsenom)) do;
       _error_=0; 
       *desc = ' ';
       output;
    end;
    otherwise;
 end;
 
 proc print data=combine;
 run;

 data lookup;
 input partno $ quantity;
 datalines;
 A066 8
 A220 2
 A812 10
 ;
 data primary(index=(partno));
 input partno $ desc $;
 datalines;
 A021 motor
 A033 bolt
 A043 nut
 A055 radiator
 A066 hose
 A078 knob
 A220 switch
 A223 bridge
;
 data combine;
 set lookup;
 set primary key=partno;
 select(_iorc_);
    when (%sysrc(_sok)) do;
       status="available";
       output;
    end;
    when (%sysrc(_dsenom)) do;
       desc=' ';
       _error_=0;
       output;
    end;
    otherwise;
 end;
 
 proc print data=combine;
 run;
 
 data sasuser.new;
    set sasuser.keyvalues;
    set dblib.mytable (dbkey=deptno) key=dbkey;
    run;