Online File

How to use this page


Rick Aster: Professional SAS Programming Secrets: Contents

Chapter 4
Program 4b
Planets compared to dwarf planets

Tentative version | Final | Data


Tentative

This version of the program contains errors that are corrected in an exercise in the book.


*
  Professional SAS Programming Secrets
  Program 4b (tentative)
  Planets compared to dwarf planets
*;

filename planets "planet1.csv";
filename dwarf "dwarfplanet1.csv";

data work.planet;
   length planet $ 16 sequence mass radius 8;
   infile planets dsd;
   input planet sequence mass radius;
run;

data work.dwarf;
   length planet $ 16 sequence mass radius 8;
   infile dwarf dsd;
   input planet sequence mass radius;
run;

*
  Combine data.
*
data work.orbital;
   length bodytype $ 12;
   set work.planet (in=big) work.dwarf (in=small);
   if big then body = 'Planet';
   else body = 'Dwarf Planet';
   log_radius = log10(radius) + 3;
   log_mass = log10(mass) + 21;
run;

*
  Summary statistics.
*;
title1 'Planets and Dwarf Planets';
proc summary data=work.orbital nway
    print n mean min max;
   class bodytype;
   var mass radius;
   label mass='Mass (10^21 kg)' radius='Radius (km)';
run;

*
  Plots.
*;
options nocenter;
proc plot data=work.orbital;
   plot mass*radius=bodytype;
run;
   plot log_mass*log_radius='o' $ planet;
run;
quit;

Final

The final, corrected version of the program.


*
  Professional SAS Programming Secrets
  Program 4b
  Planets compared to dwarf planets
*;

filename planets "planet1.csv";
filename dwarf "dwarfplanet1.csv";

data work.planet;
   length planet $ 16 sequence mass radius 8;
   infile planets dsd;
   input planet sequence mass radius;
run;

data work.dwarf;
   length planet $ 16 sequence mass radius 8;
   infile dwarf dsd;
   input planet sequence mass radius;
run;

*
  Combine data.
*;
data work.orbital;
   length bodytype $ 12;
   set work.planet (in=big) work.dwarf (in=small);
   if big then bodytype = 'Planet';
   else bodytype = 'Dwarf Planet';
   log_radius = log10(radius) + 3;
   log_mass = log10(mass) + 21;
run;

*
  Summary statistics.
*;
title1 'Planets and Dwarf Planets';
proc summary data=work.orbital nway
    print n mean min max;
   class bodytype;
   var mass radius;
   label mass='Mass (10^21 kg)' radius='Radius (km)';
run;

*
  Plots.
*;
options nocenter;
proc plot data=work.orbital;
   plot mass*radius=bodytype;
run;
   plot log_mass*log_radius='o' $ planet;
run;
quit;

Data

These initial steps from the program create SAS data sets that are used in other programs throughout the book.


*
  Professional SAS Programming Secrets
  Program 4b-data steps
  Planets compared to dwarf planets
*;

filename planets "planet1.csv";
filename dwarf "dwarfplanet1.csv";

data work.planet;
   length planet $ 16 sequence mass radius 8;
   infile planets dsd;
   input planet sequence mass radius;
run;

data work.dwarf;
   length planet $ 16 sequence mass radius 8;
   infile dwarf dsd;
   input planet sequence mass radius;
run;

*
  Combine data.
*;
data work.orbital;
   length bodytype $ 12;
   set work.planet (in=big) work.dwarf (in=small);
   if big then bodytype = 'Planet';
   else bodytype = 'Dwarf Planet';
   log_radius = log10(radius) + 3;
   log_mass = log10(mass) + 21;
run;

 O /\

Global
Statements

RICK ASTER

SAS

BOOKS

Tech | Dictionary

Download | Rastinate

Rick Aster

Professional SAS Programming Secrets

Contents/Online Files

Corrections