• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / SAS / SAS right() Function – Right Align Character Variables in Data Step

SAS right() Function – Right Align Character Variables in Data Step

April 12, 2022 Leave a Comment

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.

Other Articles You'll Also Like:

  • 1.  SAS let – Create User-Defined Macro Variables in Your SAS Code
  • 2.  SAS If Then Statements with Multiple Variables
  • 3.  SAS Remove Formats from Dataset with PROC DATASETS
  • 4.  SAS call symput – Create Macro Variables in Data Step
  • 5.  SAS if then else – Write Conditional Expressions for Multiple Conditions
  • 6.  intcx SAS – Find Time Periods Between Two Dates in SAS Data Step
  • 7.  SAS Proper Case – Capitalize First Letter of Word with propcase Function
  • 8.  SAS where in – Subset Data by Multiple Values in Data Step
  • 9.  SAS Not Equal – Check if a Variable is Not Equal to Another in Data Step
  • 10.  How to Select First 100 Observations of SAS Dataset

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy