An official website of the United States government

Case Listing Exercise 2: Exporting Data into SAS

left-img

Use the Export button to export data from the results matrix, export results as a text file, and generate SAS code to read the file.

Exercise

Export the data from Exercise 1b Result Session to a tab-delimited text file, including SAS code for reading in the new file.

Key Points

  • The Export button on the Actions menu can be used to export data displayed in a case listing or other matrix.
  •  Matrix results can be exported to a text file, with several formatting options available.
  • The Generate SAS code to read data option automatically creates an output (.sas) file containing the necessary SAS programming code to read in the data file created in the export.

Instructions

Step 1:  Open Case Listing 1b's Results

  1. Start SEER*Stat.
  2. Open the matrix file you saved in Case Listing Exercise 1b. The filename should be "Case Listing Exercise 1b.slm".
  3. If you did not save the output for exercise 1b you may open our version of the output:  Case Listing Exercise 1b Session (sl, 75.3 KB) (sl, 75.3 KB). (Use Case Listing Exercise 1b Session ALT (sl, 72.8 KB) (sl, 72.8 KB) if you do not have access to the Research Plus Data.) Open our session, execute it, and then save the matrix. Case listing examples are provided as session files instead of results matrices to ensure they may only be opened by those who have signed a SEER data use agreement and have permission to view individual records.

Step 2:  Change Values Displayed to Unformatted

  1. Highlight all of the columns in the matrix.  From the Actions menu, select the Highlight/Format button and then select All Columns.  You can also do this using Ctrl+A.
  2. Right click on any one of the selected column headers and select Display As > Unformatted

Step 3:  Select Export Options

  1. From the Actions menu select the Export button. The Export dialog opens displaying various available options for exporting text files.
  2. The top two selection boxes are used to specify the location of your exported data file and an accompanying data dictionary.  These files are both required and have default values based on the current matrix, if it was saved.  You can change the locations or names of these files by clicking the associated Browse buttons.
  3. Click the Generate SAS code to read data checkbox to create a SAS program that will import and format the data. After enabling the SAS code creation, several default options will be checked below, which are generally recommended when creating a file for use with SAS.  You can customize those options as appropriate for your programming needs.  The file name and location of the SAS program will be based on the file name and location of the data file specified at the top.  These can be modified if desired.

If you do not have SAS, you can use this same export functionality to create a comma-delimited “.csv” file which can be read by other software tools.  To do this, you need to change the extension of the data file name to “.csv” rather than “.txt”.  Then select “Comma” as the field delimiter and check the box to Output Variable Names Before Data. Or, use the CSV Defaults button to automatically set these options.

Step 4:  Export the Matrix Data and SAS Program

  1. Select the OK button to export the data as specified. An Export progress dialog opens and will close when finished.
  2. After a successful export, three files will be created in the paths you specified. 
    • The “.txt” file is the exported data in a tab-delimited text file. 
    • The “.sas” file is the SAS code that can be used to read the data directly.  This program includes the necessary file assignment, formats, input statement, formatting assignments and label assignments. 
    • The “.dic” the file is a computer-readable data dictionary describing the exported data. You will not need this file if you are importing directly into SAS.
  3. Compare your results to these files created based on the Exercise 1b Matrix File: key.case2.dic (dic, 52.0 KB) and key.case2.sas (sas, 63.5 KB). Note that only the “.dic” and “.sas” files are included, as case data cannot be shared publicly.
right-img