
We may receive data from various sites in clinical studies, and each site may enter data in its preferred format (Upper, Lower Case). We may desire to convert all of our character values to UPCASE, PROPCASE, or LOWCASE when working with such data.
Different internal codes represent uppercase and lowercase values, so you won't get a match if you test for a value like R for a variable when the real value is r. Therefore, before performing any logical comparisons, it is usually beneficial to convert all character values to either uppercase or lowercase.
These three functions change the Case of the argument.
♦ Character case can be changed to Upper or Lower using UPCASE and LOWCASE, respectively.
♦PROPCASE, which stands for "proper case," lowercase the remaining letters, and capitalizes the first character of each "word."
♦ To force the PROPCASE function to capitalize each word, the default delimiter is a space.
The second optional argument to this function is a list of delimiters.
Here is an example
Data _Null_;
SOCTERM=’Cardiac disorders’;
Up_Soc= Upcase (SOCTERM);
Lo_Soc = Lowcase (SOCTERM);
Prop_Soc = Propcase (SOCTERM);
Put Up_Soc = Lo_Soc = Prop_Soc =;
Run;
If we get this data, the task is to create a new dataset that includes the subjects who were randomly assigned to Active Treatment and experienced Adverse Events.
Data Test;
Length Patid 3 Trt $7 AE $10;
Input Patid Trt $ AE $;
Datalines;
101 active nausea 102 placebo no
105 active No 1
08 Active insomnia
109 ACTIVE Dizziness
110 Placebo Bodypain
;
Run;
Converting the cases of both TRT and AE to uppercase Data Modi;
Set Test;
Trtup = Upcase (Trt);
Aeup = Upcase (Ae);
Run;
Data Final (Drop=Trtup Aeup);
Set Modi;
Where Trtup=’ACTIVE’ and Aeup ne ‘NO’;
Run;
ANY FUNCTIONS:
These functions return the first position of ANY DIGIT, ALPHA, ALNUM, PUNCT, or SPACE in the String of characters.
Syntax: ANY***** (String, Startpos);
♦ DIGIT = any digit
♦ ALPHA = any character
♦ ALNUM = any character or digit
♦ PUNCT = any punctuation
♦ SPACE = any space
ANYALNUM FUNCTION:
This function is used to find the position of the first instance of any alphanumeric character, such as an upper- or lowercase letter or number, and return it. The function returns a 0 if none are found. This function can start its search anywhere in the String, if desired, search from right to left by passing in an optional parameter.
Syntax: ANYALNUM (character-value <, start>);
If the start value is positive, the search goes from left to right;
If the value is negative, the search goes from right to left.
Data _Null_;
String = ‘S02-P107 has Nausea’;
ADF1= ANYDIGIT (String);
ADF2= ANYDIGIT (String,6);
ADF3= ANYDIGIT (String,-25);
APF= ANYPUNCT (String);
ASF=ANYSPACE (String);
AAF=ANYALPHA (String);
AANF=ANYALNUM (String);
Put ADF1= ADF2= ADF3= APF= ASF= AAF= AANF=;
Run;
ANYDIGIT (String): ANYDIGIT is a function that takes a string as input and checks if it contains any digits.
It returns true if the String contains at least one digit and false if it does not. This function helps validate input and perform operations based on the presence of digits in a string.
♦ ANYDIGIT (String, 6) ANYDIGIT is a function that checks whether a string contains at least 6 digits.
It returns true if the String contains 6 or more digits and false if it does not. This function helps verify a specific number of digits in a string.
♦ ANYDIGIT (String,-25)The input value "-25" is invalid for the function ANYDIGIT. The function expects a positive integer value as the second parameter to specify the number of digits to check for in the String. Please provide a valid positive integer value for the second parameter.
♦ ANYPUNCT (String)ANYPUNCT is a function that checks whether a given string contains any punctuation characters. Punctuation characters are defined as any character that is not a letter, digit, or whitespace. Examples of punctuation characters include commas, periods, semicolons, hyphens, and brackets.
♦ ANYSPACE (String) The ANYSPACE function determines whether a given string contains whitespace characters. Whitespace characters include spaces, tabs, and newline characters.
♦ ANYALPHA (String) ANYALPHA is a function that checks whether a given string contains at least one alphabetic character. It returns true if the String contains at least one letter and false if it does not. This function helps validate input and ensure that a string contains alphabetic characters.
♦ ANYALNUM (String)The ANYALNUM function checks if a given string contains any alphanumeric characters, including letters and digits. It returns true if the String contains at least one alphanumeric character and false if it does not.
INDEX, INDEXC, AND INDEXW FUNCTIONS
INDEX and INDEXC functions return the position where the char or String of characters first occurs in the String. INDEXW function searches for the entire word.
Syntax:
♦ INDEX (String, Search String)
♦ INDEXC (String, Search String)
♦ INDEXW (String, Search Word)
Data _Null_;
String = ‘THIS IS SASI, A SAS ANALYST’;
Ind_val = INDEX (String, ‘SAS’);
Indc_val = INDEXC (String, ‘SAS’);
Indw_val = INDEXW (String, ‘SAS’);
Put Ind_val = Indc_val = Indw_val =;
Run;
INDEX (String, ‘SAS’) searches for the substring ‘SAS’ in the String and returns the position of Nine (9) when it encounters the String SAS, i.e., in SASI.
INDEXC (String, ‘SAS’) searches the String for either ‘S’ or ‘A’ and returns the position of Four (4) when it first encounters the letter ‘S’. i.e., in THIS
INDEXW (String, ‘SAS’) searches the String for the word ‘SAS’ and returns the position of 17 where if first finds ‘SAS’ i.e., exact word SAS.
FIND, FINDC, AND FINDW FUNCTIONS
The FIND, FINDC, and FINDW functions are used in spreadsheet software, such as Microsoft Excel, to locate the position of a specific character or substring within a cell. The FIND function is used to find the position of a particular character or substring within a cell, while the FINDC function is used to find the position of a case-sensitive character or substring.
The FINDW function finds the position of a specific character or substring within a cell, ignoring any punctuation or white space. These functions are particularly useful for manipulating and analyzing large data sets, as they allow users to quickly and easily locate specific information within a spreadsheet.
Syntax:
♦ FIND (String, Search String, Startpos, Modifier);
♦ FINDC (String, Search String, Startpos, Modifier);
The "modifiers" and "starting position" parameters can be specified using the find function, which likewise looks for a search string within a string. There are two modifiers: "t" and "i." The "t" modifier removes trailing blanks from the String, while the "i" modifier instructs SAS to ignore the Case. SAS is informed of the starting position in the String, indicating where to start.
Data _Null_;
String=’This is SASI, a SAS Analyst’;
Fnd_Val = Find (String, ‘S’);
Fndi_Val =Find (String, ‘S’, ‘i’);
Fndsp_val =Find (String, ‘S’,15);
Put Fnd_Val= Fndi_Val= Fndsp_val=;
Run;
COUNT and COUNTC Functions:
These functions count the occurrences of a String in a bigger character String. ;
Syntax:
♦ COUNT (String, Search String, <Modifier>);
♦ COUNTC (String, Search String, <Modifier>);
Modifiers: I = Ignore Case, T = Remove Leading and Trailing Blanks Data _Null_;
String = ‘Lp lp de lp LP gh lp’;
Nst_Val = COUNT (String, ‘lp’);
Cst_Val = COUNT (String, ‘LP’);
Ict_Val = COUNT (String, ‘lp’, ‘I’);
Ccnt_Val = COUNTC (String, ‘lp’);
Iccnt_Val = COUNTC (String, ‘lp’, ‘I’);
Put Nst_Val = Cst_Val = Ict_Val = Ccnt_Val = Iccnt_Val =; Run;
♦ Nst_Val count all the occurrences of ‘lp’ in the String and hence returns a value
of 3.
♦ Cst_Val count all the occurrences of ‘LP’ in the String and returns a value of 1.
♦ Ict_Val count all the occurrences of ‘lp’ and ‘LP’ due to ‘I’ modifier in the String and hence returns value of 5.
♦ Ccnt_Val count all the occurrences of ‘l’ as well as ‘p’ in the String and hence re- turn the value of 7.
♦ Iccnt_Val count all the occurrences of ‘l’,’L’,’p’, and ‘P’ in the String due to the ‘I’ modifier and hence returns the value of 10.
These are the few character functions of SAS; moreover, in the next blog, we shall discuss the remaining SAS character functions in detail.
In conclusion, the Character Functions of SAS are essential tools for manipulating and analyzing character data. With the ability to extract substrings, concatenate strings, and perform various other operations, SAS users can efficiently and effectively handle character data in their analysis.
By mastering these functions, users can save time and improve the accuracy of their results. Whether you are a beginner or an experienced SAS user, understanding and utilizing these functions can greatly enhance your data analysis skills. So, start exploring the world of SAS character functions today and take your data analysis to the next level!
Find a course provider to learn SAS
Java training | J2EE training | J2EE Jboss training | Apache JMeter trainingTake the next step towards your professional goals in SAS
Don't hesitate to talk with our course advisor right now
Receive a call
Contact NowMake a call
+1-732-338-7323Enroll for the next batch
SAS Course Online Training
- Jun 6 2025
- Online
SAS Certification Course
- Jun 9 2025
- Online
SAS Certification Course
- Jun 10 2025
- Online
SAS Certification Course
- Jun 11 2025
- Online
SAS Course Online Training
- Jun 12 2025
- Online
Related blogs on SAS to learn more

SAS Character Functions Demystified: A Comprehensive Guide
Master the power of SAS character functions and learn how to streamline your data processing tasks.

From Data to Graphs: Harnessing SAS/GRAPH for Effective Analysis
Learn how to effectively analyze and present your data with this comprehensive guide to SAS/GRAPH.

Introduction to SAS/Library
In this blog, we shall discuss introduction to SAS and its library in detail

Importing Data into a SAS Data Set: Effective Methods and Techniques
we have discussed how to import data into SAS data set, best practices for data reading in SAS, and how to create a dataset

Comprehensive Guide to SAS Functions
Learn how to leverage SAS functions to streamline your data analysis and understand the features of SAS functions.

INTRODUCTION TO SAS
We have discussed What is SAS, variables in SAS, six attributes of SAS stores and many other unique concepts of SAS.

SAS to help British Forces to hunt down Nazi Criminals!
As the SAS empowers the professionals to accomplish various success, it has also revealed it’s to open the secrets and postwar exploits helping the government to hunt down the Nazi crime people.

SAS Factory Miner will take your business analysis to next level!
SAS gained significant reach across the globe by providing a reliable platform for advanced statistical analytics. As the more and more organizations grow their need to acquire analytical software, SAS skills

Welcome SAS Factory Miner which takes your business analysis to next level!
SAS gained significant reach across the globe by providing a reliable platform for advanced statistical analytics. As the more and more organizations grow their need to acquire analytical software, SAS

SAS unveils Viya, destined to be the foundation of future products
The ability to analyze, manage and modify data from multiple types of sources makes SAS an unique and popular data analytic software suite in the world. The software suite already become friendly with the non-technical users with its GUI (Graphical U
Latest blogs on technology to explore

What Does a Cybersecurity Analyst Do? 2025
Discover the vital role of a Cybersecurity Analyst in 2025, protecting organizations from evolving cyber threats through monitoring, threat assessment, and incident response. Learn about career paths, key skills, certifications, and why now is the be

Artificial intelligence in healthcare: Medical and Diagnosis field
Artificial intelligence in healthcare: Medical and Diagnosis field

iOS 18.5 Is Here: 7 Reasons You Should Update Right Now
In this blog, we shall discuss Apple releases iOS 18.5 with new features and bug fixes

iOS 18.4.1 Update: Why Now is the Perfect Time to Master iPhone App Development
Discover how Apple’s iOS 18.4.1 update (April 2025) enhances security and stability—and why mastering iPhone app development now is key to building future-ready apps.

What is network security Monitoring? A complete guide
In the digital world, we have been using the cloud to store our confidential data to register our details; it can be forms, applications, or product purchasing platforms like e-commerce sites. Though digital platforms have various advantages, one pri

How to Handle Complex and Challenging Projects with Management Skills
Discover actionable strategies and essential management skills to effectively navigate the intricacies of challenging projects. From strategic planning to adaptive problem-solving, learn how to lead your team and achieve exceptional outcomes in compl

What are the 5 phases of project management?
A streamlined approach to ensure project success by breaking it into five essential stages: Initiation, Planning, Execution, Monitoring & Controlling, and Closing. Each phase builds on the other, guiding the team from concept to completion with clear

About Microsoft Job Openings and Certification Pathway to Explore Job Vacancies
Explore exciting Microsoft job openings across the USA in fields like software engineering, data science, cybersecurity, and more. Enhance your career with specialized certifications and land top roles at Microsoft with Sulekha's expert courses.