How can I convert strings to uppercase, lowercase, and proper case in SAS?

In SAS, you can use the UPCASE, LOWCASE, and PROPCASE functions to convert strings to uppercase, lowercase, and proper case, respectively. UPCASE takes a string and converts all letters to uppercase, LOWCASE converts all letters to lowercase, and PROPCASE capitalizes the first letter of each word. For example, SAS would become SAS with UPCASE, sas with LOWCASE, and Sas with PROPCASE. Each of these functions takes the original string as an argument and returns the modified string.


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.

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

x