The SAS right() function gives us the ability to right align character variables.
data k;
a = 'this is a string with some trailing blanks ';
b = right(a);
put b=;
run;
/* Output: */
a=this is a string with some trailing blanks
b= this is a string with some trailing blanks
When working with strings and character variables in SAS, the ability to manipulate and change their values easily can be very valuable.
One such change we can do is right align a character variable. The SAS right() function right aligns character variables.
If you have trailing blanks, you can use right() to move those blanks to the beginning of the value.
The difference between this and using strip() is that the variable length will stay the same when using right().
Below is an example of how to use the SAS right() function in SAS.
data k;
a = 'this is a string with some trailing blanks ';
b = right(a);
put b=;
run;
/* Output: */
a=this is a string with some trailing blanks
b= this is a string with some trailing blanks
Using the SAS left() Function to Left Align Character Variables
If you want to left align a character variable, we can use the SAS left() function. The left() function does the opposite of what right() does.
If you have leading blanks in your character variables, left() will left align your character variable and move the leading blanks to the end of the value.
Below is an example of how to use the SAS left() function in SAS.
data k;
a = ' this is a string with some leading blanks';
b = left(a);
put b=;
run;
/* Output: */
a= this is a string with some leading blanks
b=this is a string with some leading blanks
Hopefully this article has been useful for you to learn how to use the SAS right() function.