h1

Uppercase or Lowercase with SAS?

February 9, 2008

uppercase.jpg

When a programming language does not deal the same way with words having different cases, one says it is case-sensitive. What about SAS? Is it case-sensitive?

1. Words not affected by changes in case: most of the time SAS does not deal differently whether uppercase or lowercase is used. Here are a few examples:

  • SAS syntax (data, proc, do, if, filename, etc.)
  • SAS library names (libname orig_data ‘C:/’;)
  • SAS data sets (data demo; set DEMO;)
  • Variables name (age, AGE, Age)

If you look into you metadata using SAS dictionaries or proc contents procedure, you’ll see that all library names follow a standard notation regardless the original input name. Please note the exception of variable names which still appear in dictionaries with their original notation.

Tip: Lowercases are easier to read. Therefore you’re highly recommended to use them. You can save uppercases for special occasions, for recognising bits in your code.

2. Quoted strings are case-sensitive: here are three case-sensitive examples:

  • Values of character variables (cntry=’UK’;)
  • Variables label (label cntry=’Country’;)
  • Data sets labels (data demo (label=(‘Demography Panel’);)

Those three values are strings defined within quotes. Therefore, cntry=’UK’ is different from cntry=’Uk’.

3. Avoid mistakes using two SAS functions, UPCASE and LOWCASE: to check the value of a variable regardless its case, you can make your comparison of standardised records (all uppercased or all lowercased). Otherwise you may end up missing out some records. Two functions are available UPCASE() and LOWCASE().

4. Example using the UPCASE function with a dictionary: I personally use the UPCASE and LOWCASE functions to select records from SAS dictionaries. Here is an example where all records from the TABLES dictionary are selected when they refer to the WORK library.

proc sql ;
select *
from dictionary.tables
where upcase(libname)=’WORK’;
quit;

One comment

  1. A nice feature are also the (pre-defined) shortcuts CTRL+Shift+L or +U (only for the enhanced editor), which convert all selected text into lowercase or uppercase respectively. The shortcut can be changed via the ‘enhanced editor keys’-dialog.
    This is often useful to format text inserted by copy+paste.



Leave a Comment