![]() Chapter Contents |
![]() Previous |
![]() Next |
| UPDATE |
| Valid: | in a DATA step |
| Category: | File-handling |
| Type: | Executable |
Syntax |
UPDATEmaster-data-set<(data-set-options)>
transaction-data-set<(data-set-options)>
|
| Range: | The name can be a one-level name (for example, HEALTH), a two-level name (for example, IN.HEALTH), or one of the special SAS data set names. |
| Tip: | Special missing values, however, are the exception and will replace values in the master data set even when MISSINGCHECK (the default) is in effect. |
| Default: | MISSINGCHECK |
| Details |
Even when UPDATEMODE=MISSINGCHECK is in effect, you
can replace existing values with missing values by using special missing value
characters in the transaction data set. To create the transaction data set,
use the MISSING statement in the DATA step. If you define one of the special
missing values
A through
Z for the transaction data
set, SAS updates numeric variables in the master data set to that value.
For more information about defining and using special missing value characters, see MISSING .
| Comparisons |
| Examples |
data ohio.qtr1; update ohio.jan ohio.week4; by store; run;
Master Data Set
HEALTH
OBS ID NAME TEAM WEIGHT
1 1114 sally blue 125
2 1441 sue green 145
3 1750 joey red 189
4 1994 mark yellow 165
5 2304 joe red 170
Transaction Data Set
FITNESS
OBS ID NAME TEAM WEIGHT
1 1114 sally blue 119
2 1994 mark yellow 174
3 2304 joe red 170
options nodate pageno=1 linesize=80 pagesize=60;
/* Sort both data sets by ID */
proc sort data=health;
by id;
run;
proc sort data=fitness;
by id;
run;
/* Update Master with Transaction */
data health2;
length STATUS $11;
update health(rename=(weight=ORIG) in=a)
fitness(drop=name team in=b);
by id ;
if a and b then
do;
CHANGE=abs(orig - weight);
if weight<orig then status='loss';
else if weight>orig then status='gain';
else status='same';
end;
else status='no weigh in';
run;
options nodate ls=78;
proc print data=health2;
title 'Weekly Weigh-in Report';
run;
Weekly Weigh-in Report 1 OBS STATUS ID NAME TEAM ORIG WEIGHT CHANGE 1 loss 1114 sally blue 125 119 6 2 no weigh in 1441 sue green 145 . . 3 no weigh in 1750 joey red 189 . . 4 gain 1994 mark yellow 165 174 9 5 same 2304 joe red 170 170 0 |
options nodate pageno=1 linesize=80 pagesize=60; /* Create the Master Data Set */ data payroll; input ID SALARY; datalines; 011 245 026 269 028 374 034 333 057 582 ; /* Create the Transaction Data Set */ data increase; input ID SALARY; missing A _; datalines; 011 376 026 . 028 374 034 A 057 _ ; /* Update Master with Transaction */ data newpay; update payroll increase; by id; run; proc print data=newpay; title 'Updating with Missing Values'; run;
Updating with Missing Values 1
OBS ID SALARY
1 1011 376
2 1026 269 <=== value remains 269
3 1028 374
4 1034 A <=== special missing value
5 1057 . <=== regular missing value |
| See Also |
Statements:
| |||||||||||
System
Option:
| |||||||||||
| Reading, Modifying, and Combining SAS Data Sets in SAS Language Reference: Concepts | |||||||||||
| Data Set Options |
![]() Chapter Contents |
![]() Previous |
![]() Next |
![]() Top of Page |
Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.