UPCASE, LOWCASE & PROPCASE


!) Function: UPCASE

Purpose: To  change all letters to uppercase.
                          
                     NOTE: The corresponding fuction LOWCASE changes uppercase to lowcase


Syntax: UPCASE(character-value)     
              
            character-value is any SAS character value.

            If a length has not been previously assigned, the length of the resulting
            variable will be the length of the argument

Example:

***Primary function: UPCASE

***Other function: DIM;

data mixed;

  length a b c d e $ 1;

  input a b c d e x y;

  datalines;

  M f P p D 1 2

  m f m F M 3 4

;

run; 

data upper;

  set mixed;

  array all_c[*] _character_;

  do i = 1 to dim(all_c);

    all_c[i] = upcase(all_c[i]);

  end;

  drop i;

run;

title 'Listing of Data Set UPPER';

proc print data=upper noobs;

run;

Output

Explanation

Remember that uppercase and lowercase values are represented by different internal codes, so if you are testing for a value such as Y for a variable and the actual value is y, you will not get a match. Therefore, it is often useful to convert all character values to either uppercase or lowercase before doing your logical comparisons.

In this program, _CHARACTER_ is used in the array statement to represent all the character variables in the data set MIXED. Inspection of the following listing verifies that all lowercase values were changed to uppercase.


II) Function: LOWCASE

Purpose: To change all letters to lowercase.

Syntax: LOWCASE(character-value)

                character-value is any SAS character value.

                 Note: The corresponding function UPCASE  changes lowercase to uppercase.

                 If a length has not been previously assigned, the length of the resulting variable                                  will be the length of the argument.

Example:

***Primary function: LOWCASE;

data lowcase;

  Input ID : $3. Unit : $1. Weight;

  Unit = lowcase(Unit);

  if Unit eq 'k' then Wt_lbs = 2.2*Weight;

  else if Unit = 'l' then Wt_lbs = Weight;

datalines;

001 k 100

002 K 101

003 L 201

004 l 166

;

run;

title "Listing of Data Set WT";

proc print data=wt noobs;

run;

Output

Explanation

This program demonstrates a common problem—dealing with character data in mixed case.
Here you see that the values of the variable Unit are sometimes in uppercase and sometimes
in lowercase. A simple way to solve this problem is to use the LOWCASE function to ensure
that all values of Unit will be in lowercase.

You could also have used the UPCASE function to convert all the Unit values to uppercase.

Note: If you have mixed case data, you can use the $UPCASE informat to convert the values
to uppercase as they are being read. There is no corresponding $LOWCASE informat.

The remainder of the program is straightforward: after you convert all the values of Unit to
lowercase, you only have to check for lowercase k's and l's to determine whether you need to
multiply the Weight value by 2.2 or not.


III) Function: PROPCASE

Purpose:
To capitalize the first letter of each word in a string.

Syntax: PROPCASE(character-value <,delimiters>)

Character-value is any SAS character value.

 Delimiters An optional list of word delimiters. The default delimiters are blank, forward slash, hyphen, open parenthesis, period, and tab.

If a length has not been previously assigned, the length of the resulting variable will be the length of the argument.

Example:

data proper;

  input Name $60.;

  Name = propcase(Name);

  datalines;

  ronald cODy

  THomaS eDISON

  albert einstein

  ;

run;

title "Listing of Data Set PROPER";

proc print data=proper noobs;

run;

Output









Explanation
In this program, you use the PROPCASE function to capitalize the first letter of the first and
last names





Comments

Popular posts from this blog

Function :MDY