Online File

How to use this page


Rick Aster: Professional SAS Programming Shortcuts: Contents

Chapter 78
Program
Arithmetic


DATA _NULL_;
   INFILE IN UNBUFFERED TRUNCOVER;
   FILE OUT;

   PUT 'MATH  Select option:'
       / @5 '1  Add two numbers'
       / @5 '2  Multiply two numbers'
       / @5 'Q  Quit';
   INPUT LINE $80.;
   SELECT(SCAN(UPCASE(LINE), 1, ' ;'));
      WHEN('1') DO;
         PUT 'Enter the two numbers to add.';
         INPUT LINE $80.;
         TERM1 = SCAN(LINE, 1, ' ,;+*&');
         TERM2 = SCAN(LINE, 2, ' ,;+*&');
         SUM = SUM(0, TERM1, TERM2);
         PUT 'The sum is ' SUM :BEST16.;
         END;
      WHEN('2') DO;
         PUT 'Enter the two numbers to multiply.';
         INPUT LINE $80.;
         FACTOR1 = SCAN(LINE, 1, ' ,;+*&');
         FACTOR2 = SCAN(LINE, 2, ' ,;+*&');
         IF FACTOR1 AND FACTOR2 THEN PRODUCT = FACTOR1*FACTOR2;
         ELSE PRODUCT = 0;
         PUT 'The product is ' PRODUCT :BEST18.;
         END;
      WHEN('Q') STOP;
      OTHERWISE ;
      END;
RUN;

 O /\

Global
Statements

RICK ASTER

SAS

BOOKS

Tech | Dictionary

Download | Rastinate

Rick Aster

Professional SAS Programming Shortcuts

Contents/Online Files

Corrections

Catalog Page