Skip to Main Content

SAS Tutorials: Importing Data into SAS OnDemand for Academics

If you want to work with your own data in SAS OnDemand for Academics, you'll first need to upload it to your account. This tutorial shows how to upload and import SAS and non-SAS data files (such as Excel and CSV) into SAS ODA for analysis.

How to Get Your Own Data into SAS OnDemand for Academics

When starting a data analysis project in SAS OnDemand for Academics, your data files may or may not be in the SAS data file format (*.sas7bdat). Your data might be an Excel spreadsheet, an SPSS dataset, or a text or CSV file.

Regardless of what format your data is in, the process of getting your data into your SAS OnDemand for Academics account requires two steps. First, you must upload the file to your SAS OnDemand for Academics account -- that is, your data file must actually be uploaded to the cloud. Then, you must "import" the uploaded file into SAS Studio (using a process that is similar to what you would do with "desktop" SAS). The first step is unique to those using SAS OnDemand for Academics (if you were using "desktop" SAS, you could simply import the file directly from your computer), but fortunately only needs to be done once.

In this tutorial, we'll cover how to get data files from your computer into your SAS OnDemand for Academics account so that you can analyze them.

Uploading Data Files to Your SAS OnDemand for Academics Account

If you are using SAS OnDemand for Academics and have data files you want to work with in the program, you will need to upload data to your account. This goes for ANY dataset you want to work with in SAS ODA, including "native" SAS datasets (*.sas7bdat) or other formats such as Excel and CSV.

To upload a file to SAS ODA:

  1. In the Navigation pane, click Server Files and Folders.
  2. Left-click on the folder you want to upload the data file to (usually "Files (Home)" or a folder within that directory). Then click Upload. (Note that the Upload button will not be clickable until a folder location is selected, so if it's greyed out, make sure you've selected a folder.)

    The Upload icon is directly underneath the Server Files and Folders heading in the Navigation pane.

  3. The Upload Files window will open. Click Choose Files, then choose the data file on your computer to upload.

    Screenshot of the Upload Files window in SAS OnDemand for Academics after selecting a file to upload.

  4. SAS will show the name(s) and size(s) of the file(s) you selected. To complete the upload, click Upload.
  5. If successful, you should see the data file(s) appear in the directory you selected in step 2:

    After completing the upload, the file should appear in the directory you selected.

At this stage, if you have uploaded a SAS dataset file (*.sas7bdat) and have already mapped a library to the folder where the data file is located, you can skip the next part of the tutorial and start working with the data right away! However, if you have uploaded a text, CSV, Excel, SPSS, or other non-SAS format, you'll need to proceed to the next step: importing your uploaded data.

If you have SAS code files (*.sas) on your computer that you want to use in SAS OnDemand for Academics, you can upload them to your account using these same steps. After uploading *.sas files to your account, you can open and edit them just like a SAS script created directly in ODA.

Importing Uploaded Non-SAS Format Data

After your datafiles have been uploaded to your SAS OnDemand for Academics account, you can import the data into a SAS data step. The easiest way to do so is to use the Import Data task:

  1. Click Tasks and Utilities in the Navigation pane, then click Import Data.

    Icons for creating and deleting tasks and refresh. Drop downs for My tasks, tasks, and utilities. Utilities includes options for import data, queries, and creating new SAS Program

    This will create a new tab in the work area, titled Import Data 1.

    Import Data program with split windows.

  2. You can decide to drag and drop your files or select a file to import. In our case, the Excel file with the sample data is located in our Sample data folder. (Remember: when using SAS OnDemand for Academics, your data must be uploaded into the Server Files and Folders tab. If you do not see any data files in this window, you most likely need to upload them; see the previous section on uploading data to SAS ODA.)

  3. Once you’ve chosen the Excel file with the data, click Open. SAS will populate the file information and generate code for importing.

    The settings for the Import Data tool.

  4. To run the code, click the Run button (running man icon) to execute the code.

  5. Once you’ve executed the code, you can check the Log and see if any errors have occurred. If successful, the Log window should tell us how many observations and variables the new dataset contains.

    The standard Log Notes if importing data was successful. Will include number of observations and variables, as well as the time it took to run the import.

    Additionally, you can preview the dataset in the Output Data tab.

    A table of the output data in the output tab. Can select variable names to be displayed in the table.

  6. If you are satisfied with the code automatically generated within the import process, you have the option to save the Import task by clicking the Save button (floppy disk icon). This will create a *.ctl file in your SAS ODA account. We highly recommend doing this so that you have a record of how you imported the data, and can repeat the process later if necessary.

Understanding the Import Syntax

Let's take a closer look at the syntax that SAS generates when using the Import tool and understand what each line is doing:

The code tab with automatically generated code.

The first four lines are comments -- they do not contain executable code, and exist only as notes for human readers. The notes contain the name and location of the imported file, and the date that the import code was generated.

The first executable line of code is

%web_drop_table(WORK.IMPORT);

This particular command "clears out" any data in the system saved under the WORK.IMPORT name. You might notice that this command looks very different than the PROC IMPORT and PROC CONTENTS commands. Notice the percent symbol (%) at the start of the line: this tells us that %web_drop_table is a user-defined macro command. In this case, it's a function that SAS themselves defined to quickly delete a particular dataset. If you've imported another dataset into SAS using the Import task under the name WORK.IMPORT and want to keep it, make sure you save it under a name other than WORK.IMPORT, or else you will lose it!

The first pertinent line starts with the FILENAME statement, which specifies the path to the file containing the data to import. In particular, it assigns the nickname REFFILE to the full file path where our data is located. This means that we can simply type the nickname REFFILE in the PROC IMPORT step instead of having to write out the full file path.

The next block of code is the PROC IMPORT statement, which triggers the data import action. Note the first semicolon is not until the third line. This is because the syntax includes quite a few options associated with the PROC IMPORT statement:

  • The OUT option tells SAS where to put the new SAS dataset it is creating – in this case we told it to put the new SAS dataset “import” in the Work library.
  • The DATAFILE option points to the file directory of the dataset you are importing.
  • The DBMS option tells SAS what engine to use to read the data (in this case, the XLSX engine). This value will depend on what type of file you're importing.
  • GETNAMES=YES instructs SAS to use the first row of the file as variable names.

The PROC IMPORT code in this step is very similar to the PROC IMPORT code one would use for "desktop" SAS, so for more information about PROC IMPORT, see our Importing Excel Files into SAS tutorial.

Following the PROC IMPORT command, SAS generates code for PROC CONTENTS, which displays information about the newly-imported dataset (WORK.IMPORT).

Results tab with the results of running the code for PROC CONTENTS.

PROC CONTENTS is a standard SAS procedure; for more information about how to use and understand it, see the Summarizing Dataset Contents with PROC CONTENTS tutorial.

Tutorial Feedback