Online File

How to use this page


Rick Aster: Professional SAS Programming Secrets: Contents

Chapter 5
Program 5h
PARENTHESIZE routine


*
  Professional SAS Programming Secrets
  Program 5h
  PARENTHESIZE routine
*;
proc fcmp outlib=work.cmp.txt;
subroutine parenthesize(string $);
   outargs string;
   
   * Return string unchanged if no spaces for parentheses. *;
   arglength = lengthm(string);
   targetlength = lengthn(string) + 2;
   if targetlength > arglength then return;
   
   * Positions of first and last nonblank characters. *;
   n1 = notspace(string);
   n2 = lengthn(string);
   
   * Add parentheses before and after nonblank characters. *;
   string = substrn(string, 1, n1 - 1) || '(' ||
       substrn(string, n1, n2 - n1 + 1) || ')'  ||
       substrn(string, n2 + 1);
   return;
   endsub;
quit;

 O /\

Global
Statements

RICK ASTER

SAS

BOOKS

Tech | Dictionary

Download | Rastinate

Rick Aster

Professional SAS Programming Secrets

Contents/Online Files

Corrections