To capitalize the first letter of a word and make a string variable’s letters all proper case in a SAS data step, we can use the SAS propcase() function.
data data_new;
set data;
proper_case_word = propcase(word);
run;
When working with strings in our datasets, it can be useful for comparison or display purposes to convert strings to have all uppercase, all lowercase letters, or all words with the first character capitalized.
In a SAS data step, we can use the SAS propcase() function to easily convert a string variable to have all first letters capitalized.
Let’s we have the following SAS dataset.
data data;
input word $ 10.;
datalines;
this
is
a
dataset
with
some
strings.
;
run;
We can easily make all of these strings proper case with the SAS propcase() function. The SAS propcase() function will convert the first letter to uppercase and all the other letters to lowercase.
data data_new;
set data;
proper_case_word = propcase(word);
run;
/* Output: */
word proper_case_word
1 this This
2 is Is
3 a A
4 dataset Dataset
5 with With
6 some Some
7 strings. Strings.
If you’d like to send all letters to uppercase, you can use the SAS upcase() function. If you’d like to send all letters to lowercase, you can use the SAS lowcase() function.
Hopefully this article has been useful for you to learn how to use the SAS propcase() function to convert strings to proper case in a SAS data step.