SAS – Lowercase (lowcase) / Uppercase (upcase) / Proper Case (propcase)

This post was kindly contributed by AFHood Analytics Group - Blogs » SAS - go there to comment and to read the full post.

We can’t stress the importance handling character case correctly. Here are the two functions you need to know and use correctly.

In order to convert all characters in a sting to lowercase, use the LOWCASE function. Example:

data ds_2;

set ds_1;

*convert it to lowercase;

new_char_var=lowcase(OLD_CHAR_VAR);

run;

In order to convert all characters in a sting to uppercase, use the UPCASE function. Example:

data ds_2;

set ds_1;

*convert it to uppercase;

NEW_CHAR_VAR=upcase(old_char_var);

run;

We can’t stress the importance of keeping this functionality in mind. Many a SAS script has gone awry because a developer didn’t take character case into account when using conditional or search statements.

TIP: A solid programming practice is to convert everything to lowercase before storing it. There are exceptions to this (like names, etc), but they can be handled on a case basis.

Also note the PROPCASE function. It capitalizes the first letter of each word in a string. Example:

data ds_2;

set ds_1;

New_Prop_Var=propcase(old_char_var);

put New_Prop_Var;

run;

This Is The New Prop Var.

This post was kindly contributed by AFHood Analytics Group - Blogs » SAS - go there to comment and to read the full post.