SAS: Lowercase, Uppercase & Proper Case

This tutorial explains how to convert a string to lowercase, uppercase and proper case in SAS, along with examples.

The descriptions and syntax of LOWCASE, UPCASE, PROPCASE, ANYLOWER, and ANYUPPER functions are as follows:

  • LOWCASE: Converts a string to lowercase.
    Syntax: lowercase_string = lowcase(original_string);
  • UPCASE: Converts a string to uppercase.
    Syntax: uppercase_string = upcase(original_string);
  • PROPCASE: Converts a string to proper case.
    Syntax: propercase_string = propcase(original_string);
  • ANYLOWER: Returns position of first lowercase character.
    Syntax: position = anylower(original_string);
  • ANYUPPER: Returns position of first uppercase character.
    Syntax: position = anyupper(original_string);
Sample Dataset

Let's create a sample SAS dataset that will be used in the examples of this tutorial.

data mydata;
input company $ 1-20;
cards;
google
gooGle
Microsoft
APPLE
;
run;

How to Convert Strings to Uppercase

The following code uses the upcase() function to convert the values in the "company" variable to uppercase, and the result is stored in the new variable "company_new".

data example;
set mydata;
company_new = upcase(company);
run;
Convert Strings to Uppercase in SAS

How to Convert Strings to Lowercase

The following code uses the lowcase() function to convert the values in the "company" variable to lowercase, and the result is stored in the new variable "company_new".

data example;
set mydata;
company_new = lowcase(company);
run;
How to Convert Strings to Lowercase in SAS

How to Convert Strings to Proper Case

The following code uses the propcase() function to convert the values in the "company" variable to proper case, and the result is stored in the new variable "company_new".

Proper case refers to a style where the first letter of each word is in uppercase, while the remaining letters are in lowercase. For example, consider the sentence: "hello world". In proper case, it would be written as: "Hello World".

data example;
set mydata;
company_new = propcase(company);
run;
Convert Strings to Proper Case in SAS

How to Detect Lowercase and Uppercase Letters

The following code calculates the positions of the first lowercase and uppercase characters in the "company" variable using the ANYLOWER and ANYUPPER functions. The results are stored in the "lower_position" and "upper_position" variables.

data example;
set mydata;
lower_position = ANYLOWER(company);
upper_position= ANYUPPER(company);
run;
Position of Lowercase and Uppercase Letters in SAS
Related Posts
Spread the Word!
Share
About Author:
Deepanshu Bhalla

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has over 10 years of experience in data science. During his tenure, he worked with global clients in various domains like Banking, Insurance, Private Equity, Telecom and HR.

0 Response to "SAS: Lowercase, Uppercase & Proper Case"

Post a Comment

Next → ← Prev