SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
nit123
Obsidian | Level 7

are the variables and file names in SAS case sensitive?

 

 

data set;
    set sasdata .chemists;
    if jobcode = 'Chem2'
        then description = 'Senior Chemist';
    else description = 'Unknown';
run;

A value for the variable JOBCODE is listed below:

JOBCODE
chem2

 

output:  ?

 

 

the following file downloaded from SAS->help->learn sas programming

 

proc print data=clinic.stress2;
run;

 

/* modified file name */

proc print data=clinic.Stress2;
run;

 

output is same for both print statements

7 REPLIES 7
PGStats
Opal | Level 21

Keep on experimenting! You will find that file names, library names, variable names and language elements are NOT case sensitive but that operations on string variables (e.g. name = "John") ARE case sensitive. Thus, when you want to make string operations case insensitive, you must take precautions (e.g. upcase(name) = "JOHN").

PG
monei011monei01
Calcite | Level 5

I have found one place where case sensitivity occurs. I have a dataset in a data library and from within SAS EG I right click on the dataset and choose rename. If I rename the dataset to a name that includes uppercase characters, SAS EG can no longer "open" the dataset using right click "open"

Kurt_Bremser
Super User

Within the file system, the names have to be all lowercase; within in SAS code, the names are case insensitive, with an exception: if you need to query the dictionary tables, LIBNAME and MEMNAME are all uppercase.

monei011monei01
Calcite | Level 5

"Within the file system, the names have to be all lowercase" is not entirely true. I can create a file in both unix and widows at the operating system level where the name can be mixed case, all lower case, or all uppercase.  Under unix I can create a file name that includes special characters and blanks (probably not a practice that is sympathetic to other users or unix command users!). It is just that SAS has some expectations about what the name of a file that is a SAS dataset should be called and perhaps what the case of the name is on disk. SAS / EG allows you to see two views of a dataset. One is the view of the dataset as a member of a SAS data library, and one as a view of the file in the file system. The library view presents all dataset names as uppercase, regardless of what their physical file name is on disk with extension sas7bdat. This is the same in SAS Studio under SAS Viya. The File view in SAS / EG shows the actual file name including the .sas7bdat extension. SAS / EG also uses the same dialogue of choices you can access from a right click on the object in either view. If you deliberately rename the dataset file name in the file view so that its name includes uppercase characters, then it becomes un-openable in SAS/EG. But this only happens if there is not a libname assigned to that same directory. Very particular I know, but a trap that can catch you if you are not careful.  SAS dates from before the existence of either Windows or Unix. It has not become more relaxed and  flexible in this area of naming objects as the operating systems have evolved to provide a better user experience.

Kurt_Bremser
Super User

Of course you can have mixed case in UNIX filenames, but SAS won't recognize those. It will find them as .sas7bdat files and show them in a library listing, but won't be able to open them as datasets.

This is what I meant.

 

wangjeifei1
Calcite | Level 5

To be clear, this role only applies to the file name, not the file path. You can have a mixed case in your file path with no issue(see below). Only the file name must be lowercase

wangjeifei1_0-1736871987602.png

 

 

Even more interesting, this role is only for sas7bdat file, the other files(like csv, excel) do not follow it

wangjeifei1_0-1736873512361.png

 

Tom
Super User Tom
Super User

When you ask SAS to reference a dataset  the text you use in the code for the memname (the name of the member in a SAS library) can be in any case you want.  But on UNIX SAS will look for and use a file with that membername (and the .sas7bdat extension) in lowercase only.   Since the on the Unix file system filenames are case sensitive filenames with any uppercase letters will not be seen as datasets by SAS.

 

And yes when referencing other types of files like CSV files, (really any file other than SAS objects like datasets and catalogs and index files) then you do have to match the filename case used in the code with the filename case used in the file system.

 

 

Note that SAS probably also looks for datasets using lowercase filenames on Windows, but since on the Windows file system filenames are case insensitive it does not really matter.

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 22295 views
  • 3 likes
  • 6 in conversation