The UPDATE statement is a specialized transaction-processing tool in SAS, designed to merge a "Master" dataset with a "Transaction" dataset. Unlike the MERGE statement, which simply overwrites or combines columns, UPDATE is built with specific business logic for data persistence, ensuring that your master records are refreshed only with relevant, non-missing information.
Type : CREATION_INTERNE
Examples use generated data (datalines) or SASHELP.
| 1 | DATA master; |
| 2 | INPUT common $ animal $ plant $; |
| 3 | DATALINES; |
| 4 | a Ant Apple |
| 5 | b Bird Banana |
| 6 | c Cat Coconut |
| 7 | d Dog Dewberry |
| 8 | e Eagle Eggplant |
| 9 | f Frog Fig |
| 10 | ; |
| 11 | RUN; |
| 12 | |
| 13 | DATA plantNew; |
| 14 | INPUT common $ plant $; |
| 15 | DATALINES; |
| 16 | a Apricot |
| 17 | b Barley |
| 18 | c Cactus |
| 19 | d Date |
| 20 | e Escarole |
| 21 | f Fennel |
| 22 | ; |
| 23 | RUN; |
| 24 | |
| 25 | DATA master2; |
| 26 | update master plantNew; |
| 27 | BY common; |
| 28 | RUN; |
| 29 | PROC PRINT DATA=master2; RUN; |
| 1 | DATA master; |
| 2 | INPUT common $ animal $ plant $; |
| 3 | DATALINES; |
| 4 | a Ant Apple |
| 5 | b Bird Banana |
| 6 | c Cat Coconut |
| 7 | d Dog Dewberry |
| 8 | e Eagle Eggplant |
| 9 | f Frog Fig |
| 10 | ; |
| 11 | RUN; |
| 12 | |
| 13 | DATA plantNewDupes; |
| 14 | INPUT common $ plant $; |
| 15 | DATALINES; |
| 16 | a Apricot |
| 17 | b Barley |
| 18 | c Cactus |
| 19 | d Date |
| 20 | d Dill |
| 21 | e Escarole |
| 22 | f Fennel |
| 23 | ; |
| 24 | RUN; |
| 25 | |
| 26 | DATA master; |
| 27 | update master plantNewDupes; |
| 28 | BY common; |
| 29 | RUN; |
| 30 | PROC PRINT DATA=master; RUN; |
| 1 | DATA master; |
| 2 | INPUT common $ animal $ plant $; |
| 3 | DATALINES; |
| 4 | a Ant . |
| 5 | c Cat Coconut |
| 6 | d Dog Dewberry |
| 7 | e Eagle Eggplant |
| 8 | f Frog Fig |
| 9 | ; |
| 10 | RUN; |
| 11 | |
| 12 | DATA minerals; |
| 13 | INPUT common $ plant $ mineral $; |
| 14 | DATALINES; |
| 15 | a Apricot Amethyst |
| 16 | b Barley Beryl |
| 17 | c Cactus . |
| 18 | e . . |
| 19 | f Fennel . |
| 20 | g Grape Garnet |
| 21 | ; |
| 22 | RUN; |
| 23 | |
| 24 | DATA master; |
| 25 | update master minerals; |
| 26 | BY common; |
| 27 | RUN; |
| 28 | |
| 29 | PROC PRINT DATA=master; RUN; |
| 1 | DATA master; |
| 2 | update master minerals updatemode=nomissingcheck; |
| 3 | BY common; |
| 4 | RUN; |
| 5 | PROC PRINT DATA=master; |
| 6 | title "Updated Data Set master"; |
| 7 | title2 "With Values Updated to Missing"; |
| 8 | RUN; |