Previous Page | Next Page

Importing and Exporting External Data

Importing Data from a Flat File

Importing data enables you to read data from an existing external file and create a SAS table from it. In this section, you import the file that was created in the previous section. Note that when you import a file using SAS/ASSIST software, the file must be in fixed column format.


Instructions

  1. To import data from an external file, selectTasks [arrow] Data Management [arrow] Import DataThe Import Data from Flat File window appears.

    Import Data from Flat File Window

    [Import Data from Flat File Window]

  2. Select Data file to import. The Select External File Name window appears.

    Select External File Name Window

    [Select External File Name Window]

  3. In the External file name field, type the name of the external file that you created in Exporting a File. Use the operating environment guidelines shown in Examples of Operating Environment-Specific Physical Pathnames (where USERID represents your userid). For this example, use the external file HOUSDATA .

  4. Select Filename to indicate that you typed the physical file name of the file.

  5. Select OK. The Import Data from Flat File window reappears.

  6. Select Output table. The Specify Output Table window appears.

    Specify Output Table Window

    [Specify Output Table Window]

  7. Type the name of the SAS table that you want to create using the data from the external file. For this example, type EXTHOUSE . Refer to SAS Tables for information about table naming.

    You can store the data temporarily or permanently. For this example, store the data temporarily.

    • If you want to store the data only for the length of the SAS session, then select Temporary. The data are stored in a temporary table called WORK.EXTHOUSE, which is deleted when you end the SAS session.

    • If you want to store the data permanently, then select Permanent. A list of existing SAS librefs appears.

      Select the libref for the location where you want to store the data, for example, the SASUSER libref. Once the import is complete, the table EXTHOUSE is stored in the SASUSER libref and remains there until you delete it.

  8. Select OK. The Import Data from Flat File window reappears.

  9. Select OK. The Define Fields window appears.

    Define Fields Window

    [Define Fields Window]

    The first line of the external file appears below the rule line. Notice that there is no space between the number of bathrooms (1) and the address (Sheppard Avenue). In fact, there are no spaces between any of the columns because you saved this file with fixed column widths rather than with delimiters between data values. Because numeric columns are right-justified, while character columns are left-justified, the data values in the bathrooms column appear to be directly adjacent to the data values in the address column. Be careful not to mark them as one data value.

  10. In the Define Fields window, use angle brackets (< and >) to mark the width of each field as shown in the following display. If a field has a length of only 1, then use the vertical bar (|) to mark it.

    Make sure that you allow for the greatest width possible for each field value so that you do not inadvertently truncate some of your data.

    Define Fields Window with Fields Defined

    [Define Fields Window with Fields Defined]

  11. Select OK. The Import window appears.

    Import Window

    [Import Window]

  12. Type the following information for each column at the bottom of the window. Press TAB to move among the fields. To move to the next or previous column at the bottom of the window, use the scroll bar in the lower right corner of the window.

    • Type a name for each column. For this example, type Style for the name of the first column. Type over the existing name (V1). See SAS Tables for information on column naming.

    • You can change the column type, if needed. A column may be either numeric or character. Move the cursor to the type you want and press ENTER to select it. For this example, leave the type as CHAR.

    • You can type a format in the Format field, if needed. A format determines how the values appear when they are displayed by SAS software. For a list of formats, type a question mark (? ) in the Format field and press ENTER. Move the cursor to the format you want and press ENTER to select it. For this example, leave the format blank.

    • You can type an informat in the Informat field, if needed. An informat determines how the values are read from the external file into the SAS table. For a list of informats, type a ? in the Informat field and press ENTER. Move the cursor to the informat you want and press ENTER to select it. For this example, leave the informat blank.

      See SAS Language Reference: Concepts for more information on formats and informats.

    • Type a label for each column. For this example, type Style of House . SAS software displays the column label you assign instead of the column name. A label can contain from 1 to 40 characters.

    • Type the information for the remaining five columns as shown in the following table. Use the scroll bar in the lower right corner of the window to access the next column.

    Assigning Column Information
    Name Type Format Informat Label
    SQFEET NUM

    Square Feet
    BEDROOMS NUM

    Number of Bedrooms
    BATHS NUM

    Number of Bathrooms
    ADDRESS CHAR

    Street Address
    PRICE NUM COMMA9. COMMA9. Price of House

  13. After you finish typing the information for all the columns, selectData [arrow] Create Data Set ("Data set" is another term for "table.") The Create Data Set window appears with a prompt that asks whether you want to be prompted to enter new values for bad values or whether you want a report sent to the log. For this example, select VERIFY so that you will be prompted to correct any errors in the data as they are imported.

  14. Select OK. A message appears at the bottom of the window with the statistics of the number of records processed.

    [Statistics on the number of records processed]

  15. Press ENTER to clear the statistics. The Import window reappears. A note appears in the message area stating the number of observations (rows) and variables (columns) in the table.

    You can Edit created data set or Browse created data set from the Data menu on the menu bar.

  16. When you finish browsing or editing your table, selectFile [arrow] Closeto close the FSBROWSE or FSEDIT window. Then, from the Import window, selectFile [arrow] Closeto return to the WorkPlace menu.

Previous Page | Next Page | Top of Page