/***************************************************************************************************************** SAS file name: Modify_Statement File location: _________________________________________________________________________________________________________________ Purpose: To demonstrate how to use the Modify Statement in the SAS Data Step Author: Peter Clemmensen Creation Date: 18/01/2019 This program supports the example page "Using the SAS Data Step Modify Statement" on SASnrd.com *****************************************************************************************************************/ /* Example Data Set */ data Master; input ID $ Value; datalines; 1 1 2 2 3 3 4 4 5 5 ; data Trans; input ID $ Value; datalines; 1 10 2 20 4 10 4 20 4 30 5 . 6 60 ; /* Create simple index on the Master data set */ proc datasets library=work nolist; modify Master; index delete _all_; index create ID / nomiss; run;quit; /* Use Modify Statement with KEY= Option to update the Master data set */ data Master; set Trans(rename=(Value=TransValue)); /* 1 */ modify Master key=ID / unique; /* 2 */ select (_iorc_); /* 3 */ when (%sysrc(_sok)) do; /* 4 */ if TransValue ne . then do; Value=TransValue; replace; end; end; when (%sysrc(_dsenom)) do; /* 5 */ Value=TransValue; output; _error_=0; end; otherwise do; put 'Unexpected I/O Error: ' errormessage; _error_=0; /*stop;*/ end; end; run;