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