![]() Chapter Contents |
![]() Previous |
![]() Next |
| MODIFY |
| Valid: | in a DATA step |
| Category: | File-handling |
| Type: | Executable |
| Restriction: | Cannot modify the descriptor portion of a SAS data set, such as adding a variable |
Syntax |
MODIFY master-data-set <(data-set-option(s))>
transaction-data-set <(data-set-option(s))>
<NOBS=variable> <END=variable> <UPDATEMODE=MISSINGCHECK| NOMISSINGCHECK>; BY by-variable; |
MODIFY master-data-set <(data-set-option(s))>
KEY=index </ UNIQUE> <NOBS=variable> < END=variable>
;
|
MODIFY master-data-set <(data-set-option(s))>
<NOBS=variable> POINT=variable;
|
MODIFY master-data-set
<(data-set-option(s))> <NOBS=variable>
<END=variable>;
|
Note:
| Restriction: | Specify this data set only when the DATA step contains a BY statement. |
| Explanation: |
The variable, which
is initialized to zero, is set to 1 when the MODIFY statement reads the last
observation of the data set being modified (for sequential access )
or the last observation of the transaction data set (for matching access ).
It is also set to 1 when MODIFY cannot find a match for a KEY= value (random
access ).
|
| Restriction: | Do not use this argument in the same MODIFY statement with the POINT= argument. POINT= indicates that MODIFY uses random access. The value of the END= variable is never set to 1 for random access. |
| Requirement: | When using the POINT= argument, include one or both of the following: Because POINT= reads only the specified observations, SAS cannot detect an end-of-file condition as it would if the file were being read sequentially. Because detecting an end-of-file condition terminates a DATA step automatically, failure to substitute another means of terminating the DATA step when you use POINT= can cause the DATA step to go into a continuous loop. |
| Restriction: | You cannot use the POINT= option with any of the following: |
| Restriction: | You can use POINT= with compressed data sets only if the data set was created with the $POINTOBS= data set option set to 'YES'. |
| Tip: | If the POINT= value does not match an observation number, SAS sets the automatic variable _ERROR_ to 1. |
| Featured in: | Modifying Observations Located by Observation Number |
| Default: | MISSINGCHECK |
| Details |
Matching Access
Modifying Observations Using a Transaction Data Set
shows the matching access method.
Duplicate BY Values
Direct Access by Indexed Values
Modifying Observations Located by an Index
shows the direct-access-by-indexed-values method.
Duplicate Index Values
Handling Duplicate Index Values shows how to handle duplicate index values.
Direct (Random) Access by Observation NumberModifying Observations Located by Observation Number shows the direct (random) access by observation number method.
![[cautend]](../common/images/cautend.gif)
Sequential Access
Controlling I/O
shows how to use the automatic variable _IORC_ and the SYSRC autocall macro.
Keep in mind the following as you work with these statements:
Replacing and Removing Observations and Writing Observations to Different SAS Data Sets
shows how to use the OUTPUT, REMOVE, and REPLACE statements to write observations.
| Comparisons |
For information on DBMS replacement rules, see the SAS/ACCESS documentation.
Duplicate BY Values.
| Input Data Set for Examples |
The examples modify the INVTY.STOCK data set. INVTY.STOCK contains these variables:
libname invty 'SAS-data-library';
data invty.stock(index=(partno));
input PARTNO $ DESC $ INSTOCK @17
RECDATE date7. @25 PRICE;
format recdate date7.;
datalines;
K89R seal 34 27jul95 245.00
M4J7 sander 98 20jun95 45.88
LK43 filter 121 19may96 10.99
MN21 brace 43 10aug96 27.87
BC85 clamp 80 16aug96 9.55
NCF3 valve 198 20mar96 24.50
KJ66 cutter 6 18jun96 19.77
UYN7 rod 211 09sep96 11.55
JD03 switch 383 09jan97 13.99
BV1E timer 26 03jan97 34.50
;
| Examples |
data invty.stock; modify invty.stock; recdate=today(); run;
A printing of INVTY.STOCK shows that RECDATE has been modified:
INVTY.STOCK 1
PARTNO DESC INSTOCK RECDATE PRICE
K89R seal 34 14MAR97 245.00
M4J7 sander 98 14MAR97 45.88
LK43 filter 121 14MAR97 10.99
MN21 brace 43 14MAR97 27.87
BC85 clamp 80 14MAR97 9.55
NCF3 valve 198 14MAR97 24.50
KJ66 cutter 6 14MAR97 19.77
UYN7 rod 211 14MAR97 11.55
JD03 switch 383 14MAR97 13.99
BV1E timer 26 14MAR97 34.50 |
This DATA step creates ADDINV:
data addinv; input PARTNO $ NWSTOCK; datalines; K89R 55 M4J7 21 LK43 43 MN21 73 BC85 57 NCF3 90 KJ66 2 UYN7 108 JD03 55 BV1E 27 ;
This DATA step uses values from ADDINV to update INVTY.STOCK.
libname invty 'SAS-data-library';
data invty.stock; modify invty.stock addinv; by partno; RECDATE=today(); INSTOCK=instock+nwstock; run;
A printing of INVTY.STOCK shows that INSTOCK and RECDATE have been modified:
INVTY.STOCK 1
PARTNO DESC INSTOCK RECDATE PRICE
K89R seal 89 14MAR97 245.00
M4J7 sander 119 14MAR97 45.88
LK43 filter 164 14MAR97 10.99
MN21 brace 116 14MAR97 27.87
BC85 clamp 137 14MAR97 9.55
NCF3 valve 288 14MAR97 24.50
KJ66 cutter 8 14MAR97 19.77
UYN7 rod 319 14MAR97 11.55
JD03 switch 438 14MAR97 13.99
BV1E timer 53 14MAR97 34.50 |
The data set NEWP contains two variables:
data newp; input TOOL_OBS NEWP; datalines; 251.00 2 49.33 3 12.32 4 30.00 5 15.00 6 25.75 7 22.00 8 14.00 9 14.32 0 35.00 ;
This DATA step updates INVTY.STOCK:
libname invty 'SAS-data-library';
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.';
_error_=0;
stop;
end;
PRICE=newp;
RECDATE=today();
run;
A printing of INVTY.STOCK shows that RECDATE and PRICE have been modified:
INVTY.STOCK 1
PARTNO DESC INSTOCK RECDATE PRICE
K89R seal 34 14MAR97 251.00
M4J7 sander 98 14MAR97 49.33
LK43 filter 121 14MAR97 12.32
MN21 brace 43 14MAR97 30.00
BC85 clamp 80 14MAR97 15.00
NCF3 valve 198 14MAR97 25.75
KJ66 cutter 6 14MAR97 22.00
UYN7 rod 211 14MAR97 14.00
JD03 switch 383 14MAR97 14.32
BV1E timer 26 14MAR97 35.00 |
This example uses the KEY= option to identify observations to retrieve by matching the values of PARTNO from ADDINV with the indexed values of PARTNO in INVTY.STOCK. ADDINV is created in Modifying Observations Using a Transaction Data Set.
libname invty 'SAS-data-library';
data invty.stock; set addinv; modify invty.stock key=partno; INSTOCK=instock+nwstock; RECDATE=today(); run;
A printing of INVTY.STOCK shows that INSTOCK and RECDATE have been modified.
INVTY.STOCK 1
PARTNO DESC INSTOCK RECDATE PRICE
K89R seal 89 14MAR97 245.00
M4J7 sander 119 14MAR97 45.88
LK43 filter 164 14MAR97 10.99
MN21 brace 116 14MAR97 27.87
BC85 clamp 137 14MAR97 9.55
NCF3 valve 288 14MAR97 24.50
KJ66 cutter 8 14MAR97 19.77
UYN7 rod 319 14MAR97 11.55
JD03 switch 438 14MAR97 13.99
BV1E timer 53 14MAR97 34.50 |
M4J7 appears twice.This DATA step creates NEWINV:
data newinv; input PARTNO $ NWSTOCK; datalines; K89R 55 M4J7 21 M4J7 26 LK43 43 MN21 73 BC85 57 NCF3 90 KJ66 2 UYN7 108 JD03 55 BV1E 27 ;
libname invty 'SAS-data-library';
/* This DATA step terminates with an error! */ data invty.stock; set newinv; modify invty.stock key=partno; INSTOCK=instock+nwstock; RECDATE=today(); run;
This message appears in the SAS log:
ERROR: No matching observation was found in MASTER data set.
PARTNO=K89R NWSTOCK=55 DESC= INSTOCK=. RECDATE=14MAR97 PRICE=.
_ERROR_=1 _IORC_=1230015 _N_=1
NOTE: Missing values were generated as a result of performing
an operation on missing values.
Each place is given by:
(Number of times) at (Line):(Column).
1 at 689:19
NOTE: The SAS System stopped processing this step because of
errors.
NOTE: The data set INVTY.STOCK has been updated. There were 0
observations rewritten, 0 observations added and 0
observations deleted. |
data invty.stock; set newinv; modify invty.stock key=partno / unique; INSTOCK=instock+nwstock; RECDATE=today(); run;
A printing of INVTY.STOCK shows that INSTOCK and RECDATE have been modified:
Results of Using the UNIQUE Option 1
PARTNO DESC INSTOCK RECDATE PRICE
K89R seal 89 14MAR97 245.00
M4J7 sander 145 14MAR97 45.88
LK43 filter 164 14MAR97 10.99
MN21 brace 116 14MAR97 27.87
BC85 clamp 137 14MAR97 9.55
NCF3 valve 288 14MAR97 24.50
KJ66 cutter 8 14MAR97 19.77
UYN7 rod 319 14MAR97 11.55
JD03 switch 438 14MAR97 13.99
BV1E timer 53 14MAR97 34.50 |
This DATA step creates NEWSHIP:
data newship;
input PARTNO $ DESC $ NWSTOCK @17
SHPDATE date7. @25 NWPRICE;
datalines;
K89R seal 14 14nov96 245.00
M4J7 sander 24 23aug96 47.98
LK43 filter 11 29jan97 14.99
MN21 brace 9 09jan97 27.87
BC85 clamp 12 09dec96 10.00
ME34 cutter 8 14nov96 14.50
;
libname invty 'SAS-data-library';
data invty.stock;
set newship;
modify invty.stock key=partno;
select (_iorc_);
when (%sysrc(_sok)) do;
INSTOCK=instock+nwstock;
RECDATE=shpdate;
PRICE=nwprice;
replace;
end;
when (%sysrc(_dsenom)) do;
INSTOCK=nwstock;
RECDATE=shpdate;
PRICE=nwprice;
output;
_error_=0;
end;
otherwise do;
put
'An unexpected I/O error has occurred.'/
'Check your data and your program';
_error_=0;
stop;
end;
end;
run;
INVTY.STOCK Data Set 1
PARTNO DESC INSTOCK RECDATE PRICE
K89R seal 48 14NOV96 245.00
M4J7 sander 122 23AUG96 47.98
LK43 filter 132 29JAN97 14.99
MN21 brace 52 09JAN97 27.87
BC85 clamp 92 09DEC96 10.00
NCF3 valve 198 20MAR96 24.50
KJ66 cutter 6 18JUN96 19.77
UYN7 rod 211 09SEP96 11.55
JD03 switch 383 09JAN97 13.99
BV1E timer 26 03JAN97 34.50
ME34 cutter 8 14NOV96 14.50 |
libname invty 'SAS-data-library';
data invty.stock invty.stock95 invty.stock97;
modify invty.stock;
if recdate>'01jan97'd then do;
output invty.stock97;
remove invty.stock;
end;
else if recdate<'01jan96'd then do;
output invty.stock95;
remove invty.stock;
end;
else do;
price=price*1.1;
replace invty.stock;
end;
run;
New Prices for Stock Rcvd in '96 1
PARTNO DESC INSTOCK RECDATE PRICE
LK43 filter 121 19MAY96 12.089
MN21 brace 43 10AUG96 30.657
BC85 clamp 80 16AUG96 10.505
NCF3 valve 198 20MAR96 26.950
KJ66 cutter 6 18JUN96 21.747
UYN7 rod 211 09SEP96 12.705 |
| See Also |
Statements:
| |||||||||
| Reading, Combining, and Modifying SAS Data Sets in SAS Language Reference: Concepts | |||||||||
| SAS/ACCESS documentation | |||||||||
| SQL Procedure in SAS Procedures Guide |
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.