Online File

How to use this page


Rick Aster: Professional SAS Programming Shortcuts: Contents

Chapter 27
Program
Bubble sort of character string


DATA _NULL_;
   CHARS = 'example';

   LENGTH SWAPCHAR $ 1;
   N = LENGTH(CHARS);
   * Bubble sort: swap characters until all characters are in order. ;
   DO UNTIL (COUNT = 0);
      COUNT = 0;
      DO C = 2 TO N;
         IF SUBSTR(CHARS, C, 1) >= SUBSTR(CHARS, C - 1, 1) THEN CONTINUE;
         COUNT + 1;
         SWAPCHAR = SUBSTR(CHARS, C - 1, 1);
         SUBSTR(CHARS, C - 1, 1) = SUBSTR(CHARS, C, 1);
         SUBSTR(CHARS, C, 1) = SWAPCHAR;
         END;
      END;
      
   PUT CHARS;
RUN;

 O /\

Global
Statements

RICK ASTER

SAS

BOOKS

Tech | Dictionary

Download | Rastinate

Rick Aster

Professional SAS Programming Shortcuts

Contents/Online Files

Corrections

Catalog Page