9.1 - A Working Data Set

9.1 - A Working Data Set

Throughout this lesson, we will investigate a number of examples that illustrate how to create different informats and formats for several different variables. To do so, we will use a subset of the demographic (or "background") data collected on 638 subjects once enrolled in the National Institute of Health's Interstitial Cystitis Data Base (ICDB) Study. Not surprisingly, the ICDB Study collected data on people who were diagnosed as having interstitial cystitis! The primary reason for conducting the study was that interstitial cystitis is a poorly understood condition that causes severe bladder and pelvic pain, urinary frequency, and painful urination in the absence of any identifiable cause. Although the disease is more prevalent in women, it affects both men and women of all ages. For the ICDB Study, each subject was enrolled at one of seven clinical centers and was evaluated four times a year for as many as four years.

It will probably be helpful for you to take a peek at the background data form on which the data were collected. In order to run the SAS programs in this lesson, you'll need to save the background data set to a directory on your computer. To do so, right-click the link and select the "Save Link As" option. A Save dialog box will appear and allow you to save the data file to the location you choose on your computer.

Example 9.1

Because there are 638 observations and 16 variables in the permanent background data set icdb.back, the data on just ten subjects and nine variables are selected when creating the temporary working background data set back. The following SAS program creates the subset:


OPTIONS PS = 58 LS = 80 NODATE NONUMBER;
LIBNAME icdb 'C:\Simon\icdb\data';

DATA back;
   set icdb.back;
   age = (v_date - b_date)/365.25;
   if subj in (110051, 110088, 210012, 220004, 230006,
               310083, 410012, 420037, 510027, 520017);
   keep subj v_date b_date age sex state country race relig;
   format age 4.1;
RUN;

PROC PRINT;
  title 'Output Dataset: BACK';
RUN;
Output Dataset: BACK
Obs subj v_date b_date sex state country race relig age
1 110051 1/25/94 12/02/42 2 42 1 4 3 51.1
2 110088 2/28/95 10/03/27 2 23 1 4 2 67.4
3 210012 07/16/93 06/27/24 2 . 6 4 1 69.1
4 220004 07/27/93 08/07/72 2 38 1 4 1 21.0
5 230006 01/06/94 04/24/49 2 21 1 4 3 44.7
6 310083 01/20/95 05/13/54 1 . 17 2 1 40.7
7 410012 09/16/93 11/01/47 2 22 1 4 3 45.9
8 420037 02/02/94 0/25/41 2 22 1 4 1 52.5
9 510027 02/15/94 08/16/63 2 49 1 4 1 30.5
10 520017 11/17/93 09/24/54 2 14 1 4 1 39.1

Launch the SAS program. Then, edit the LIBNAME statement so it reflects the location where you saved the background data set. Then, run the program and review the contents of the print procedure to familiarize yourself with the structure and contents of the subset data set called back.

Note that the IF statement tells SAS which ten subjects we want included in the back data set. And, the KEEP statement tells SAS which nine variables we want included in the back data set. We will learn more about the KEEP statement in Stat 481. You might also want to note that the FORMAT statement tells SAS to use the SAS-provided w.d format to display an age as 44.7, say.

Example 9.2

We'll also need to work with an raw data file version of the subset data set. The following SAS code creates the ascii raw data file, in column format, from the temporary back data set:

DATA _NULL_;
  set back;
  file 'C:\simon\icdb\data\back.dat';
  put subj 1-6 @8 b_date mmddyy8. sex 17 race 19 
      relig 21 state 23-24 country 26-27 
      @29 age 4.1 @34 v_date mmddyy8.;
RUN;

The SAS data set name _NULL_ tells SAS to execute the DATA step as if it were creating a new SAS data set, but no observations and no variables are written to an output data set. The PUT statement tells SAS to write the variables — in the format specified — to the filename specified (back.dat) in the FILE statement. The specifications used in the PUT statement are similar to the specifications used in the INPUT statement.

Launch the SAS program. Then, edit the FILE statement so it reflects the location where you would like the raw data file saved. Then, run the program. Open the newly created back.dat file in an ascii editor, such as NotePad, to convince yourself that its structure and contents are similar to the back data set.


Legend
[1]Link
Has Tooltip/Popover
 Toggleable Visibility