Browsing and Updating SYSTEM 2000 Data |
Appending Data Described by SAS/ACCESS View Descriptors and PROC SQL Views |
You can use the APPEND procedure to append data that is described by SAS/ACCESS view descriptors and PROC SQL views to SAS data files. You can also update the data described by a view descriptor by appending to it the data from another SAS data set.
For an append operation to be successful, the variables in the BASE= (target) data set and the variables in the DATA= (source) data set must match, or you must use the FORCE= option to concatenate the data sets. The FORCE= option causes PROC APPEND to drop the extra variables and issues a warning to the user.
You can append the data described by a view descriptor to a SAS 6 or later data file and vice versa. For variables that use the longer naming conventions in SAS 7 and later or for variables that otherwise do not match, use the RENAME= data set option in PROC APPEND to rename the variables.
Appending Data to a SAS Data File |
In the following example, two managers have kept separate employee telephone lists. The Marketing manager kept records in the SYSTEM 2000 database EMPLOYEE, which is described by the view descriptor VLIB.EMPPHON. The Corporation manager kept records for the executive telephone list in the SAS 6 SAS data file MYDATA.CORPHON. The two sources must be combined to create a telephone list of employees in both departments.
The data that is described by the view descriptor VLIB.EMPPHON and the data in the SAS data file MYDATA.CORPHON are displayed in Data Described by VLIB.EMPPHON and Data in MYDATA. CORPHON.
proc print data=vlib.empphon; title 'Marketing Phone List'; run; proc print data=mydata.corphon; title 'Corporation Phone List'; run;
Data Described by VLIB.EMPPHON
Marketing Phone List 1 OBS LASTNAME FIRSTNME PHONE 1 AMEER DAVID 545 XT495 2 BROOKS RUBEN R. 581 XT347 3 BROWN VIRGINA P. 218 XT258 4 CHAN TAI 292 XT331 5 GARRETT OLAN M. 212 XT208 6 GIBSON GEORGE J. 327 XT703 7 GOODSON ALAN F. 323 XT512 8 JUAREZ ARMANDO 506 XT987 9 LITTLEJOHN FANNIE 219 XT653 10 RICHARDSON TRAVIS Z. 243 XT325 11 RODRIGUEZ ROMUALDO R 243 XT874 12 SCHOLL MADISON A. 318 XT419 13 SHROPSHIRE LELAND G. 327 XT616 14 SMITH JERRY LEE 327 XT169 15 VAN HOTTEN GWENDOLYN 212 XT311 16 WAGGONNER MERRILEE D 244 XT914 17 WILLIAMSON JANICE L. 218 XT802
Corporation Phone List 1 OBS LASTNAME FIRSTNME PHONE 1 BOWMAN HUGH E. 109 XT901 2 FAULKNER CARRIE ANN 132 XT417 3 GARRETT OLAN M. 212 XT208 4 KNAPP PATRICE R. 222 XT 12 5 KNIGHT ALTHEA 213 XT218 6 MILLSAP JOEL B. 131 XT224 7 MUELLER PATSY 223 XT822 8 NATHANIEL DARRYL 118 XT544 9 SALAZAR YOLANDA 111 XT169 10 WATERHOUSE CLIFTON P. 101 XT109
To combine the data described by these two sources, use PROC APPEND, as shown in the following program. Appended Data displays the data in the updated data file MYDATA.CORPHON. Notice that the combined data is sorted by last name. Also, because PROC PRINT was used to display the data, the variable names are used (for example, FIRSTNME), not the variable labels, which are the item names (for example, FORENAME).
proc append base=mydata.corphon data=vlib.empphon; run; proc sort data=mydata.corphon; by lastname; proc print data=mydata.corphon; title 'Corporation and Marketing Phone List'; run;
Corporation and Marketing Phone List 1 OBS LASTNAME FIRSTNME PHONE 1 AMEER DAVID 545 XT495 2 BOWMAN HUGH E. 109 XT901 3 BROOKS RUBEN R. 581 XT347 4 BROWN VIRGINA P. 218 XT258 5 CHAN TAI 292 XT331 6 FAULKNER CARRIE ANN 132 XT417 7 GARRETT OLAN M. 212 XT208 8 GARRETT OLAN M. 212 XT208 9 GIBSON GEORGE J. 327 XT703 10 GOODSON ALAN F. 323 XT512 11 JUAREZ ARMANDO 506 XT987 12 KNAPP PATRICE R. 222 XT 12 13 KNIGHT ALTHEA 213 XT218 14 LITTLEJOHN FANNIE 219 XT653 15 MILLSAP JOEL B. 131 XT224 16 MUELLER PATSY 223 XT822 17 NATHANIEL DARRYL 118 XT544 18 RICHARDSON TRAVIS Z. 243 XT325 19 RODRIGUEZ ROMUALDO R 243 XT874 20 SALAZAR YOLANDA 111 XT169 21 SCHOLL MADISON A. 318 XT419 22 SHROPSHIRE LELAND G. 327 XT616 23 SMITH JERRY LEE 327 XT169 24 VANHOTTEN GWENDOLYN 212 XT311 25 WAGGONNER MERRILEE D 244 XT914 26 WATERHOUSE CLIFTON P. 101 XT109 27 WILLIAMSON JANICE L. 218 XT802
PROC APPEND also accepts a WHERE= data set option or a WHERE statement to subset the observations from the DATA= data set that will be added to the BASE= data set, as shown in the following program. (It is assumed that the data file MYDATA.CORPHON is in its original state before executing PROC APPEND in the preceding program.) Appended Data with a WHERE= Data Set Option displays the results.
proc append base=mydata.corphon data=vlib.empphon(where=(lastname='AMEER')); run; proc print data=mydata.corphon; title2 'Appended Data with a WHERE= Data Set Option'; run;
Appended Data with a WHERE= Data Set Option
Appended Data with a WHERE= Data Set Option 1 OBS LASTNAME FIRSTNME PHONE 1 BOWMAN HUGH E. 109 XT901 2 FAULKNER CARRIE ANN 132 XT417 3 GARRETT OLAN M. 212 XT208 4 KNAPP PATRICE R. 222 XT 12 5 KNIGHT ALTHEA 213 XT218 6 MILLSAP JOEL B. 131 XT224 7 MUELLER PATSY 223 XT822 8 NATHANIEL DARRYL 118 XT544 9 SALAZAR YOLANDA 111 XT169 10 WATERHOUSE CLIFTON P. 101 XT109 11 AMEER DAVID 545 XT495
Appending Data to SAS 7 or Later Data Files |
In the previous example, if the Corporation manager kept records in a SAS 7 data file named V7.CORPHON (see Data in V7.CORPHON) and used variable names longer than eight characters, the data in VLIB.EMPPHON could be appended by using the following program:
proc append base=v7.corphon (rename (firstname=firstnme)) data=vlib.empphon; run; proc sort data=v7.corphon; by lastname; proc print data=v7.corphon; title2 'Corporation and Marketing Phone List'; run;
Corporation Phone List Obs lastname firstname phone 1 BOWMAN HUGH E. 109 XT901 2 FAULKNER CARRIE ANN 132 XT417 3 GARRETT OLAN M. 212 XT208 4 KNAPP PATRICE M. 222 XT 12 5 KNIGHT ALTHEA 213 XT218 6 MILLSAP JOEL B. 131 XT224 7 MUELLER PATSY 223 XT822 8 NATHANIEL DARRYL 118 XT544 9 SALAZAR YOLANDA 111 XT169 10 WATERHOUSE CLIFTON P. 101 XT109
In this example, the RENAME= data set option is used to reconcile a character-length discrepancy between the FIRSTNAME variable in the V7 data file and the FIRSTNME variable in the view descriptor. Data in V7.CORPHON with Appended Data from VLIB.EMPPHON shows a portion of the data in the updated data file V7.CORPHON.
Data in V7.CORPHON with Appended Data from VLIB.EMPPHON
Corporation and Marketing Phone List Obs lastname firstnme phone 1 AMEER DAVID 545 XT495 2 BOWMAN HUGH E. 109 XT901 3 BROOKS RUBEN R. 581 XT347 4 BROWN VIRGINA P. 218 XT258 5 CHAN TAI 292 XT331 6 FAULKNER CARRIE ANN 132 XT417 7 GARRETT OLAN M. 212 XT208 8 GARRETT OLAN M. 212 XT208 9 GIBSON GEORGE J. 327 XT703 10 GOODSON ALAN F. 323 XT512 11 JUAREZ ARMANDO 506 XT987 12 KNAPP PATRICE R. 222 XT 12 13 KNIGHT ALTHEA 213 XT218 14 LITTLEJOHN FANNIE 219 XT653 15 MILLSAP JOEL B. 131 XT224 16 MUELLER PATSY 223 XT822 17 NATHANIEL DARRYL 118 XT544 18 RICHARDSON TRAVIS Z. 243 XT325 19 RODRIGUEZ ROMUALDO R 243 XT874 20 SALAZAR YOLANDA 111 XT169 21 SCHOLL MADISON A. 318 XT419 22 SHROPSHIRE LELAND G. 327 XT616 23 SMITH JERRY LEE 327 XT169 24 VANHOTTEN GWENDOLYN 212 XT311 25 WAGGONNER MERRILEE D 244 XT914 26 WATERHOUSE CLIFTON P. 101 XT109 27 WILLIAMSON JANICE L. 218 XT802
Appending SAS Data to a View Descriptor |
When appending SAS data to a view descriptor, you will not be able to sort the data unless you specify an output data file. To sort the data in the view descriptor, you would have to sort the SYSTEM 2000 database, which is not recommended.
For more information about the APPEND procedure, see the Base SAS Procedures Guide.
Copyright © 2007 by SAS Institute Inc., Cary, NC, USA. All rights reserved.