The MODIFY statement extends the capabilities of the DATA step by enabling you to
modify IMS data that is accessed by a view descriptor or a
SAS data file without creating an additional copy of the file. To use the MODIFY statement with
a view descriptor, you must define Update privileges in the PCB associated with the
view, even if your program does not intend to modify the data.
You can specify either a view descriptor or a SAS data file as the
data set to be opened for update by using the MODIFY statement. In the following example,
the data set to be opened for update is the view descriptor Vlib.CustInfo, which describes
data in the IMS sample database AcctDBD. See
Example Data for the code used to generate this view descriptor and the
access descriptor MyLib.Account. The updates made to Vlib.CustInfo are used to change the data in the
AcctDBD database. In order to update Vlib.CustInfo, you create a
SAS data set, MyData.PhoneNum, to supply transaction information.
The MODIFY statement updates the AcctDBD database with data from the MyData.PhoneNum
data set in the following example:
data vlib.custinfo
work.phoneupd (keep=soc_sec_number home_phone
office_phone)
work.nossnumb (keep=soc_sec_number home_phone
office_phone);
modify vlib.custinfo mydata.phonenum;
by soc_sec_number;
select (_iorc_);
when (%sysrc(_sok))
/* soc_sec_number found in ACCTDBD */
do;
replace vlib.custinfo;
output phoneupd;
end;
when (%sysrc(_dsenmr))
/* soc_sec_number not found in ACCTDBD */
do;
_error_=0;
output nossnumb;
/* stores misses in NOSSNUMB */
end;
otherwise
/* traps unexpected outcomes */
do;
put 'Unexpected error condition:
_iorc_ = ' _iorc_;
put 'for SOC_SEC_NUMBER=' soc_sec_number
'. DATA step continuing.';
_error_=0;
end;
end;
run;
For each iteration of the DATA step, SAS attempts to read one observation (or record)
of the AcctDBD database as defined by Vlib.CustInfo, based on SOC_SEC_NUMBER values
supplied by MyData.PhoneNum.
If a match on SOC_SEC_NUMBER values is found, the current segment data in AcctDBD
is replaced with the updated information in MyData.PhoneNum, then
SOC_SEC_NUMBER, HOME_PHONE and OFFICE_PHONE are stored in the PHONEUPD data file.
If the SOC_SEC_NUMBER value supplied by MyData.PhoneNum has no match in Vlib.CustInfo,
the transaction information is written to the data file NoSSNumb.
To further understand this
type of processing, be aware that for each iteration of the DATA step (that is, each execution
of the MODIFY statement), MyData.PhoneNum is processed sequentially.
For each iteration, the current value of SOC_SEC_NUMBER is used to attach a WHERE
clause to a request for an observation from Vlib.CustInfo as defined by the view.
The engine then tries to generate a retrieval request with a
qualified SSA from the WHERE clause. If the engine generates a qualified
SSA, a GET UNIQUE call is issued, and data that is defined by the view is accessed directly.
If the engine cannot generate a qualified SSA from the WHERE clause, a sequential
pass of the database is required for each transaction observation in MyData.PhoneNum.
To print the PhoneUpd
data file to see the SOC_SEC_NUMBER items that were updated, submit
the following statements.
/* Print data set named phoneupd */
proc print data=work.phoneupd nodate;
title2 'SSNs updated.';
run;
The results are shown in the following output:
Contents of the PhoneUpd Data File
The SAS System
SSNs updated.
SOC_SEC_
OBS NUMBER HOME_PHONE OFFICE_PHONE
1 667-73-8275 703-657-3098 703-645-4418
2 434-62-1234 703-645-441
3 178-42-6534 703-657-1346 703-657-1345
4 156-45-5672 703-657-5656 703-623-4257
5 657-34-3245 703-345-4346 703-355-5438
6 456-45-3462 703-657-3566 703-645-1212
To print the NoSSNumb data set to see the SOC_SEC_NUMBER items that were not updated
submit the following statements.
/* Print data set named nossnumb */
proc print data=work.nossnumb nodate;
title2 'SSNs not updated.';
run;
The results produced are shown in the following
output:
Contents of the NoSSNumb Data File
The SAS System
SSNs not updated.
SOC_SEC_
OBS NUMBER HOME_PHONE OFFICE_PHONE
1 416-41-3162 703-657-3166 703-615-1212