Chapter Contents

Previous

Next
CREATE

CREATE



Creates a SAS/ACCESS descriptor file.

Required statement
Applies to: access descriptor or view descriptor


Syntax
Details
Creating access descriptors
Creating view descriptors
Examples

Syntax

CREATE libref.descriptor-name.ACCESS|VIEW;


Details

Use CREATE to create an access or view descriptor for a PC file you want to access from the SAS system. To access a particular PC file of a supported type, you must create first an access descriptor, and then one or more view descriptors based on the access descriptor.

The descriptor name has three parts, separated by periods(.). The libref identifies a SAS data library, which is associated with a directory on the local system's disk where the descriptor will be created. The libref must already have been created using the LIBNAME statement. The descriptor-name is the name of the descriptor to be created. The third part is the descriptor type. Specify ACCESS for an access descriptor or VIEW for a view descriptor.

You can use the CREATE statement as many times as necessary in one procedure execution. That is, you can create multiple access descriptors, as well as one or more view descriptors based on these access descriptors, within the same execution of the ACCESS procedure. Or, you can create access descriptors and view descriptors in separate executions of the procedure.

You can use CREATE and UPDATE in the same PROC ACCESS block with one restriction: a CREATE statement for a view descriptor may not follow an UPDATE statement.


Creating access descriptors

When you create an access descriptor, you must place statements or groups of statements in a certain order after the PROC ACCESS statement and its options, as listed here:

  1. CREATE must be the first statement after the PROC ACCESS statement with one exception: if the block includes both CREATE and UPDATE statements, either statement may be the first in the block.

  2. Next, specify any database-description statement, such as PATH=. This information describes the location and characteristics of the PC file. These statements must be placed before any editing statements. Do not specify these statements when you create view descriptors.

    Information from database-description statements is stored in an access descriptor. Therefore, you do not repeat this information when you create view descriptors. See Chapters 5 and later for additional database-description statements for your PC file format.

  3. Next, specify any editing statements: ASSIGN, DROP, FORMAT, LIST, RENAME, RESET, and SUBSET. QUIT is also an editing statement, but using it terminates PROC ACCESS without creating your descriptor.

  4. Finally, specify the RUN statement. RUN executes the ACCESS procedure.

The order of the statements within the database-description and editing groups sometimes matters; see the individual statement descriptions for more information.

Note:   Altering a PC file that has descriptor files defined on it may cause the descriptor files to be out-of-date or invalid. For example, if you re-create a file and add a new column to the file, an existing access descriptor defined on that file does not show that column; in this case, the descriptor may still be valid. However, if you re-create a file and delete an existing column from the file, the descriptor may be invalid. If the deleted column is included in a view descriptor and this view is used in a SAS program, the program fails and an error message is written to the SAS log.  [cautionend]


Creating view descriptors

You can create view descriptors and access descriptors in the same ACCESS procedure or in separate procedures.

To create a view descriptor and the access descriptor on which it is based within the same PROC ACCESS execution, you must place the statements or groups of statements in a particular order after the PROC ACCESS statement and its options, as listed below:

  1. First, create the access descriptor as described in Creating access descriptors except omit the RUN statement.

  2. Next, specify the CREATE statement for the view descriptor. The CREATE statement must follow the PROC ACCESS statements that you used to create the access descriptor.

  3. Next, specify any editing statements: SELECT, SUBSET, and UNIQUE are valid only when creating view descriptors. FORMAT, LIST, RENAME, and RESET are valid for both view and access descriptors. FORMAT, RENAME, and UNIQUE can be specified only when ASSIGN=NO is specified in the access descriptor referenced by this view descriptor. QUIT is also an editing statement but using it terminates PROC ACCESS without creating your descriptor.

    The order of the statements within this group usually does not matter; see the individual statement descriptions for any restrictions.

  4. Finally specify the RUN statement. RUN executes PROC ACCESS.

To create a view descriptor based on an access descriptor that was created in a separate PROC ACCESS step, you specify the access descriptor's name in the ACCDESC= option in the new PROC ACCESS statement. You must specify the CREATE statement before any of the editing statements for the view descriptor.

If you create only one descriptor in a PROC step, the CREATE statement and its accompanying statements are checked for errors when you submit PROC ACCESS for processing. If you create multiple descriptors in the same PROC step, each CREATE statement (and its accompanying statements) is checked for errors as it is processed.

If no errors are found when the RUN statement is processed, all descriptors are saved. If errors are found, error messages are written to the SAS log, and processing is terminated. After you correct the errors, resubmit your statements.


Examples

The following example creates the access descriptor ADLIB.PRODUCT for the worksheet file named c:\sasdemo\specprod.wk4:

libname adlib 'c:\sasdata';

proc access dbms=wk4;
   create adlib.product.access;
   path='c:\sasdemo\specprod.wk4';
   getnames=yes;
   assign=yes;
   rename productid prodid
          fibername fiber;
   format productid  4.
          weight     e16.9
          fibersize  e20.13
          width      e16.9;
run;

The following example creates an access descriptor named ADLIB.EMPLOY for the Excel worksheet named c:\dubois\employ.xls. It also creates a view descriptor named VLIB.EMP1204 for this same file:

libname adlib 'c:\sasdata';
libname vlib 'c:\sasviews';

proc access dbms=xls;
   /* create access descriptor  */
   create adlib.employ.access;
   path='c:\dubois\employ.xls';
   getnames=yes;
   assign=no;
   list all;

   create vlib.emp1204.view;
   /* create view descriptor  */
   select empid lastname hiredate salary 
          dept gender birthdate;
   format empid 6.
          salary dollar12.2
          jobcode 5.
          hiredate datetime7.
          birthdate datetime7.;
   subset where jobcode=1204;
run;

The following example creates a view descriptor VLIB.BDAYS from the ADLIB.EMPLOY access descriptor, which was created in the previous PROC ACCESS step. Note that FORMAT could be used because the access descriptor was created with ASSIGN=NO.

libname adlib 'c:\sasdata';
libname vlib 'c:\sasviews';

proc access accdesc=adlib.employ;
   create vlib.bdays.view;
   select empid lastname birthdate;
   format empid 6.
          birthdate datetime7.;
run;


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.