![]() | ![]() | ![]() | ![]() |
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
/**************************************************************/
/* S A S S A M P L E L I B R A R Y */
/* */
/* NAME: BUG18U01 */
/* TITLE: Updating SAS Data Sets, Chapter 18 */
/* PRODUCT: BASE */
/* SYSTEM: ALL */
/* KEYS: DOC DATASTEP PRINT SORT UPDATE BY DSOPTION */
/* RENAME= FUNCTION SUM MERGE DROP */
/* PROCS: PRINT SORT */
/* DATA: */
/* */
/* SUPPORT: UPDATE: */
/* REF: SAS Language and Procedures: Usage */
/* MISC: */
/* */
/**************************************************************/
/* For simplicity the infile statement has been removed and */
/* the raw data is being read into this step via a cards */
/* statement. */
options ls=72;
title;
data master;
input id 1-8 name $ 9-27 street $ 28-47 city $ 48-62
state $ 63-64 zip $ 67-71;
cards;
1001 Ericson, Jane 111 Clancey Court Chapel Hill NC 27514
1002 Dix, Martin 4 Shepherd St. Norwich VT 05055
1003 Gabrielli, Theresa 24 Ridgetop Rd. Westboro MA 01581
1004 Clayton, Aria 14 Bridge St. San Francisco CA 94124
1005 Archuleta, Ruby Box 108 Milagro NM 87429
1006 Misiewicz, Jeremy 43-C Lakeview Apts. Madison WI 53704
1007 Ahmadi, Hafez 5203 Marston Way Boulder CO 80302
1008 Jacobson, Becky 1 Lincoln St. Tallahassee FL 32312
1009 An, Ing 95 Willow Dr. Charlotte NC 28211
1010 Slater, Emily 1009 Cherry St. York PA 17407
;
proc print data=master;
title 'The Master Mailing List Is Sorted by ID';
run;
data trans;
input id 1-8 name $ 9-27 street $ 28-47 city $ 48-62
state $ 63-64 zip $ 67-71;
cards;
1002 Dix-Rosen, Martin
1001 27516
1006 932 Webster St.
1009 2540 Pleasant St. Raleigh 27622
1011 Mitchell, Wayne 28 Morningside Dr. New York NY 10017
1002 R.R. 2, Box 1850 Hanover NH 03755
1012 Stavros, Gloria 212 Northampton Rd. South Hadley MA 01075
;
proc sort data=trans;
by id;
run;
proc print data=trans;
title 'Transaction Data Set Sorted by ID';
run;
data newlist;
update master trans;
by id;
run;
proc print data=newlist;
title 'Updated Mailing List';
run;
data yrsales;
input title $ 1-25 author $ 27-50 sales;
cards;
The Milagro Beanfield War Nichols, John 303
The Golden Gate Seth, Vikran 150
Always Coming Home LeGuin, Ursula 79
Falling through Space Gilchrist, Ellen 128
Ender's Game Card, Orson Scott 87
The Handmaid's Tale Atwood, Margaret 64
;
proc sort data=yrsales;
by title;
run;
proc print data=yrsales;
title 'Sales to Date';
title2;
title3 'Sorted by TITLE';
run;
data weeklist;
input title $ 1-25 author $ 27-50 sales;
cards;
The Milagro Beanfield War Nichols, John 32
The Golden Gate Seth, Vikran 17
Always Coming Home LeGuin, Ursula 10
Falling through Space Gilchrist, Ellen 12
The Accidental Tourist Tyler, Anne 15
The Handmaid's Tale Atwood, Margaret 8
;
proc sort data=weeklist;
by title;
run;
proc print data=weeklist;
title 'This Week''s Sales Sorted by TITLE';
run;
data totsales;
update yrsales weeklist (rename=(sales=newsales));
by title;
sales=sum(sales,newsales);
drop newsales;
run;
proc print data=totsales;
title 'Updated Year-to-Date Sales';
run;
data merged;
merge master trans;
by id;
run;
proc print data=merged;
title 'Merging the Master and Transaction Data Sets';
title2 'instead of Updating Them';
run;
These sample files and code examples are provided by SAS Institute Inc. "as is" without warranty of any kind, either express or implied, including but not limited to the implied warranties of merchantability and fitness for a particular purpose. Recipients acknowledge and agree that SAS Institute shall not be liable for any damages whatsoever arising out of their use of this material. In addition, SAS Institute will provide no support for the materials contained herein.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Statements ==> File-handling ==> UPDATE SAS Reference ==> Statements ==> File-handling ==> MERGE SAS Reference ==> Statements ==> File-handling ==> MERGE ==> with BY Common Programming Tasks ==> Combining Data Data Management ==> Manipulation and Transformation ==> Combining and Modifying Data Sets |
| Date Modified: | 2005-12-08 11:34:44 |
| Date Created: | 2005-05-23 13:46:25 |
| Product Family | Product | Host | SAS Release | |
| Starting | Ending | |||
| SAS System | Base SAS | All | n/a | n/a |



