Some of my students in my Introduction to SAS class are having trouble with a particular data set. Here are some screen shots showing how SAS can read this file in several different ways.

There are four videos that you can listen to instead of reading this handout.

Here is what SAS looks like when you fire it up.

What the SAS screen looks like when you first open it

What the SAS screen looks like when you first open it

The default arrangement is atrocious in my opinion. There may be a way to change this, but I don’t know how.

SAS screen with a blank editor window

SAS screen with a blank editor window

Here, I’ve ditched the useless left panel and maximized the EDITOR window. Load the SAS program backpain_import.sas.

libname MEDB5507
  "c:/Users/simons/Dropbox/u/DBHI/classes/2018a_sas/dat";
filename backpain
  "c:/Users/simons/Dropbox/u/DBHI/classes/2018a_sas/dat/backpain.txt";
data MEDB5507.backpain_v01 replace;
  infile backpain delimiter='09'x firstobs=2 ;
  input
    Subject
    Group $
    Match
    Age
    Height
    Weight
    Event $
    Years /* also try Years $ */
    WeekDist
    Dominant $
    DF_Iliopsoas
    DF_Rectus
    DF_ITBTFL
    DF_Hamstring
    DL_Iliopsoas
    DL_Rectus
    DL_ITBTFL
    DL_Hamstring
    NF_Iliopsoas
    NF_Rectus
    NF_ITBTFL
    NF_Hamstring
    NL_Iliopsoas
    NL_Rectus
    NL_ITBTFL
    NL_Hamstring
;
run;
proc print
    data=MEDB5507.backpain_v01;
  var Subject Group Years;
  title "Printout of first import attempt";
run;

Let’s take this apart, line by line.

libname MEDB5507
  "c:/Users/simons/Dropbox/u/DBHI/classes/2018a_sas/dat";

The LIBNAME statement takes the long and ugly path where I store my files and assigns it the nickname "MEDB5507<U+2033>. Your LIBNAME statement, of course, will look different, and you may prefer a different nickname.

filename backpain
  "c:/Users/simons/Dropbox/u/DBHI/classes/2018a_sas/dat/backpain.txt";

The FILENAME statement takes the full path and filename for the location of the file we want to use repeatedly and assigns it the nickname backpain.

data MEDB5507.backpain_v01 replace;
  infile backpain delimiter='09'x firstobs=2 ;

The DATA statement has a two part name. The part before the dot tells SAS to use the folder associated with the nickname MEDB5507. The part after the dot gives the name of the file.

The REPLACE option tells SAS that if it encounters an existing file with the same name, it’s okay to overwrite it with the new file.

  infile backpain delimiter='09'x firstobs=2 ;

The INFILE statement tells SAS where to find the input. Using the backpain nickname that we created earlier with the FILENAME statement shortens our code a bit, You could have used LIBNAME “C:/YOUR_VERY_LONG_PATH/FILENAME.TXT” and that would have worked also.

The DELIMITER option tells SAS that this is a tab delimited file. 09 is hexadecimal for the tab character. Knowing what delimiter to use is part of the challenge of reading in text data.

The FIRSTOBS option tells SAS to start on the second row and ignore what appears on the first row.

Website list of backpain data

Website list of backpain data

Here’s what the file looks like, if you don’t remember. This listing is a bit difficult to read because of the line wrapping.