Chapter Contents |
Previous |
Next |
SAS/ACCESS Software for PC File Formats: Reference |
To update DBF data, you can specify view descriptors in the SQL procedure's INSERT, DELETE, and UPDATE statements. You can also use these statements to modify SAS data files. However, the ability to update data in a DBF file is subject to the following conditions:
A summary of some of the SQL procedure statements follows:
SELECT | retrieves, manipulates, and displays
PC file data that is described by a view descriptor.
SELECT
can also use data described by a PROC SQL or DATA step view or data in a SAS
data file. A SELECT statement is usually referred to as a query
because it queries the table for information. |
DELETE | deletes rows from a SAS data file or from a DBF file that is described by a view descriptor. When you reference a view descriptor that is based on a DBF file in the DELETE statement, the records in the DBF file are marked for deletion. |
INSERT | inserts rows into a DBF file or a SAS data file. |
UPDATE | updates the data values in a DBF file or in a SAS data file. |
Because the SQL procedure is based on the Structured Query Language, it works somewhat differently than some SAS procedures. For example, the SQL procedure executes without a RUN statement when a procedure statement is submitted. The SQL procedure also displays any output automatically without using the PRINT procedure.
By default, PROC SQL uses the LABEL option to display output. LABEL displays SAS variable labels, which default to PC files column names. If you prefer to use SAS variable names in your output, specify NOLABEL in the OPTIONS statement.
For more information about this procedure, its options, and example, see the SQL procedure chapter in SAS Procedures Guide.
Reading Data with the SQL Procedure |
The asterisk (*) in the SELECT statement indicates that all the columns in VLIB.PRODUCT are retrieved. The WHERE clause retrieves a subset of the rows. The ORDER BY clause causes the data to be presented in ascending order according to the table's FIBERNAME column.
proc access dmbs=dif; create adlib.product.access; /* create access descriptor */ path="c:\sasdemo\specprod.dif"; diflabel; assign=yes; rename productid prodid; format productid 4. weight e16.9 fibersize e20.13 width e16.9; list all; create vlib.product.view; /* create view descriptor */ select all; list view; run; options nodate linesize=120; title 'DIF File Data Retrieved with a SELECT Statement'; proc sql; select * from vlib.product where cost is not null order by fibernam; quit;
PC Files Data Retrieved with a PROC SQL Query displays the query's output. Notice that the SQL procedure displays the DIF file's column names, not the SAS variable names.
PC Files Data Retrieved with a PROC SQL Query
DIF File Data Retrieved with a SELECT Statement PRODUCTID WEIGHT FIBERNAME FIBERSIZE COST PERUNIT WIDTH ------------------------------------------------------------------------------------------------------------------ 1279 1.278899910E-01 asbestos 6.3476000000000E-10 1289.64 m 2.227550050E+02 2567 1.258500220E-01 fiberglass 5.1880000000000E-11 560.33 m 1.205000000E+02 8934 1.429999950E-03 gold 2.3800000000000E-12 100580.33 cm 2.255999760E+01 |
Updating Data with the SQL Procedure |
proc sql; update vlib.empeeoc set salary=26678.24, gender='M', birthdat='28AUG1959'd where empid=123456; options linesize=120; title 'Updated Data in EMPLOYEES Table'; select empid, hiredate, salary, dept, jobcode, gender, birthdat, lastname from vlib.empeeoc where empid=123456; quit;
DBF File Data Updated with the UPDATE Statement displays the updated row of data retrieved from the view descriptor VLIB.EMPEEOC.
DBF File Data Updated with the UPDATE Statement
Updated Data in EMPLOYEES Table EMPID HIREDATE SALARY DEPT JOBCODE GENDER BIRTHDATE LASTNAME -------------------------------------------------------------------------------------- 123456 04APR1989 $26,678.24 ACC043 1204 M 28AUG1959 VARGAS |
Deleting Data with the SQL Procedure |
proc sql; delete from vlib.empeeoc where empid=346917; quit;The deleted observation is marked with an asterisk (*) in the DELETE_FLG field. This is the only indicator you have that a record in a DBF field has been marked for deletion. If you have a number of rows to delete, you could use a macro variable EMPID instead of the individual EMPID values. Doing so would enable you to change the values more easily.
%let empid=346917; proc sql; delete from vlib.empeeoc where empid=&empid; quit;
Inserting Data with the SQL Procedure |
proc sql; insert into vlib.allemp values(",346917,'02MAR1987'd,46000.33,'SHP013',204, 'F','15MAR1950'd,'SHIEKELESLAM','SHALA', 'Y.','8745'); quit;
A message is written to the SAS log to indicate that the row has been inserted, as shown in Message Displayed in the SAS Log When a Row Is Inserted:
Message Displayed in the SAS Log When a Row Is Inserted
6698 6699 6700 6701 6702 6703 proc sql; 6704 insert into vlib.allemp 6705 values(",346917,'02MAR1987'd,46000.33, 6706 'SHP013',204,'F','15MAR1950'd, 6707 'SHIEKELESLAM','SHALA','Y.', 6708 '8745'); NOTE: 1 row was inserted into VLIB.ALLEMP. 6709 quit; |
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.