Previous Page | Next Page

Understanding and Customizing SAS Output: The Basics

Representing Missing Values


Recognizing Default Values

In the following example, numeric data for male verbal and math scores is missing for 1972. Character data for gender is missing for math scores in 1975. By default, SAS replaces a missing numeric value with a period, and a missing character value with a blank when it creates the data set.

options pagesize=60 linesize=80 pageno=1 nodate;

libname admin 'SAS-data-library';
data admin.sat_scores2;
   input Test $ 1-8 Gender $ 10 Year 12-15 SATscore 17-19;
   datalines;
verbal   m 1972 .
verbal   f 1972 529
verbal   m 1975 515
verbal   f 1975 509  
math     m 1972 .
math     f 1972 489
math       1975 518
math       1975 479
;
run;

proc print data=admin.sat_scores2;
   title 'SAT Scores for Years 1972 and 1975';
run;

The following output shows the results:

Default Display of Missing Values

                       SAT Scores for Years 1972 and 1975                      1

                  Obs     Test     Gender    Year    SATscore

                   1     verbal      m       1972         .  
                   2     verbal      f       1972       529  
                   3     verbal      m       1975       515  
                   4     verbal      f       1975       509  
                   5     math        m       1972         .  
                   6     math        f       1972       489  
                   7     math                1975       518  
                   8     math                1975       479  

Customizing Output of Missing Values by Using a System Option

If your data set contains missing numeric values, you can use the MISSING= system option to display the missing values as a single character rather than as the default period. You specify the character you want to use as the value of the MISSING= option. You can specify any single character.

In the following program, the MISSING= option in the OPTIONS statement causes the PRINT procedure to display the letter M, rather than a period, for each numeric missing value.

options missing='M' pageno=1;

libname admin 'SAS-data-library';
data admin.sat_scores2;
   input Test $ 1-8 Gender $ 10 Year 12-15 SATscore 17-19;
   datalines;
verbal   m 1972
verbal   f 1972 529
verbal   m 1975 515
verbal   f 1975 509  
math     m 1972
math     f 1972 489
math       1975 518
math       1975 479
;

proc print data=admin.sat_scores2;
   title 'SAT Scores for Years 1972 and 1975';
run;

The following output shows the results:

Customized Output of Missing Numeric Values

                       SAT Scores for Years 1972 and 1975                      1

                  Obs     Test     Gender    Year    SATscore

                   1     verbal      m       1972         M  
                   2     verbal      f       1972       529  
                   3     verbal      m       1975       515  
                   4     verbal      f       1975       509  
                   5     math        m       1972         M  
                   6     math        f       1972       489  
                   7     math                1975       518  
                   8     math                1975       479  

Customizing Output of Missing Values by Using a Procedure

Using the FORMAT procedure is another way to represent missing numeric values. It enables you to customize missing values by formatting them. You first use the FORMAT procedure to define a format, and then use a FORMAT statement in a PROC or DATA step to associate the format with a variable.

The following program uses the FORMAT procedure to define a format, and then uses a FORMAT statement in the PROC step to associate the format with the variable SCORE. Note that you do not follow the format name with a period in the VALUE statement but a period always accompanies the format when you use it in a FORMAT statement.

options pageno=1;
libname admin 'SAS-data-library';

proc format;
   value xscore .='score unavailable';
run;

proc print data=admin.sat_scores2;
   format SATscore xscore.;
   title 'SAT Scores for Years 1972 and 1975';
run;

The following output shows the results:

Numeric Missing Values Replaced by a Format

                       SAT Scores for Years 1972 and 1975                      1

              Obs     Test     Gender    Year        SATscore

               1     verbal      m       1972    score unavailable
               2     verbal      f       1972                  529
               3     verbal      m       1975                  515
               4     verbal      f       1975                  509
               5     math        m       1972    score unavailable
               6     math        f       1972                  489
               7     math                1975                  518
               8     math                1975                  479

Previous Page | Next Page | Top of Page