Chapter Contents

Previous

Next
SAS/ACCESS Software for PC File Formats: Reference

Reading PC Files Data into a SAS/AF Application

The following example shows you how to use a view descriptor in a SAS/AF application just as you would any other SAS data set. In this example, you create an application by using SAS/AF software and Screen Control Language (SCL). The application enables you to enter an employee ID (EMPID in the EMPLOYEE.DBF file) in order to display the employee's name and phone extension.

Follow these steps to create a SAS/AF application that uses a view descriptor:

  1. Use PROC ACCESS to create the access descriptor ADLIB.EMPLOY and view
    descriptor VLIB.ALLEMP.
    proc access dbms=dbf;
       /* create access descriptor  */
       create adlib.employ.access;        
       path='c:\sasdemo\employee.dbf';
       assign=yes;
       format empid     6.0
              salary    dollar12.2
              jobcode   5.0
              birthdate date9.
              hiredate  date9.;
       list all;
    
       /* create vlib.allemp view */
       create vlib.allemp.view;        
       
       select all;
    run;

  2. To start building a SAS/AF PROGRAM entry for this application, submit the
    following statements:
    libname scllib 'SAS-data-library';  
       /* assign a libref */
    
      /* create the catalog entry */
    proc build
     catalog=scllib.employee.example.program;
    run;

  3. Use the features available in the DISPLAY window to create the window shown in DISPLAY Window for EXAMPLE Application. For more information about these features, refer to the online help information for SAS/AF software

DISPLAY Window for EXAMPLE Application

[IMAGE]

After designing the DISPLAY window, open the ATTR window (with the ATTR command) and change the default values for the ID and PHN attributes. The type for ID should be changed from CHAR to NUM.

The &PHN field is shown in ATTR Window for EXAMPLE Application. Notice that the field name PHN is assigned to the variable PHONE, which is listed as the alias. This variable is only four characters wide (as shown in the Length field) but the name PHONE is five characters long. Therefore, a shorter field name is assigned--three characters ( PHN) plus the &. For more information about window attributes, refer to the online help information for SAS/AF software.

ATTR Window for EXAMPLE Application

[IMAGE]

Issue the SOURCE command to open the SOURCE window so that you can enter the SCL program into it, as shown in SCL Program for the Source Window.


SCL Program for the Source Window
/* SCL program to be added to the Source window */ INIT: /* Open the view descriptor VLIB.ALLEMP for reading (input mode) */ dsid=open('vlib.allemp','i'); call set(dsid); return; MAIN: /* When an employee id is entered, subset the view */ /* descriptor and fetch in values for the employee's */ /* first name, last name, and phone extension */ if modified(id) and id ne _blank_ then do; rc=where(dsid,'empid = '||put(id,6.)); rc=fetch(dsid); if rc ne 0 then _msg_ = 'Employee id not found. Please re-enter'; end; return; TERM: /* Close the view descriptor */ if (dsid > 0) then dsid=close(dsid); return;

Compile and test the program. Your SAS/AF application window is displayed. Enter an employee's ID (EMPID) from EMPLOYEE.DBF, as shown in User's View of the Application.

User's View of the Application

[IMAGE]

Press ENTER and the employee's name and phone extension are automatically supplied from the DBF file, as shown in PC Files Data Supplied by the Application.

PC Files Data Supplied by the Application

[IMAGE]


Chapter Contents

Previous

Next

Top of Page

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