/***************************************************************************************************************** SAS file name: reverse_string.sas File location: __________________________________________________________________________________________________________________ Purpose: To demonstrate the Author: Peter Clemmensen Creation Date: 03/09/2020 This program supports the blog post "How to Reverse Characters in a String in SAS" on SASnrd.com *****************************************************************************************************************/ /* Reverse characters in entire string with Reverse Function */ data _null_; s = "the quick brown fox jumps over the lazy dog"; r = reverse(s); put r=; run; /* Use Revers Format */ data _null_; s = "the quick brown fox jumps over the lazy dog"; put s $revers43.; run; /* Use Revers Format and Put Function */ data _null_; s = "the quick brown fox jumps over the lazy dog"; r = put(s, $revers43.); put r=; run; /* Reverse characters in each word */ data _null_; s = "the quick brown fox jumps over the lazy dog"; length r $ 200; do i = 1 to countw(s); r = catx(" ", r, reverse(scan(s, i))); end; put r=; run;