SAS: Convert Strings to Uppercase, Lowercase & Proper Case


You can use the following methods to convert strings to uppercase, lowercase, and proper case in SAS:

Method 1: Convert String to Uppercase

new_string = UPCASE(old_string);

Method 2: Convert String to Lowercase

new_string = LOWCASE(old_string); 

Method 3: Convert String to Proper Case

new_string = PROPCASE(old_string); 

The following examples show how to use each method with the following dataset in SAS:

/*create dataset*/
data original_data;
    input team $1-20;
    datalines;
Washington wizards
Houston rockets
Boston celtics
San antonio spurs
Orlando magic
Miami heat
;
run;

/*view dataset*/
proc print data=original_data;

Example 1: Convert Strings to Uppercase

The following code shows how to create a new dataset in which all of the team names are converted to uppercase:

/*create new dataset*/
data new_data;
    set original_data;
    team = UPCASE(team);
run;

/*view new dataset*/
proc print data=new_data;

Notice that each of the team names have been converted to uppercase.

Example 2: Convert Strings to Lowercase

The following code shows how to create a new dataset in which all of the team names are converted to lowercase:

/*create new dataset*/
data new_data;
    set original_data;
    team = LOWCASE(team);
run;

/*view new dataset*/
proc print data=new_data;

Notice that each of the team names have been converted to lowercase.

Example 3: Convert Strings to Proper Case

The following code shows how to create a new dataset in which all of the team names are converted to proper case:

Note: Proper case means the first letter of each word is capitalized.

/*create new dataset*/
data new_data;
    set original_data;
    team = PROPCASE(team);
run;

/*view new dataset*/
proc print data=new_data;

Notice that each of the team names have been converted to proper case.

Additional Resources

The following tutorials explain how to perform other common tasks in SAS:

How to Use Proc Summary in SAS
How to Rename Variables in SAS
How to Create New Variables in SAS
How to Remove Duplicates in SAS

Leave a Reply

Your email address will not be published.