4.5 C
London
Thursday, December 19, 2024
HomeSASData Munging in SASSAS: Convert Strings to Uppercase, Lowercase & Proper Case

SAS: Convert Strings to Uppercase, Lowercase & Proper Case

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

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

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories