Referencing SAS Files

Referencing Permanent SAS Data Sets

To reference a permanent SAS data set in your SAS programs, use a two-level name consisting of the library name and the data set name:
libref.dataset
In the two-level name, libref is the name of the SAS library that contains the data set, and data set is the name of the SAS data set. A period separates the libref and data set name.
Figure 2.3 Two-Level Permanent SAS Name
Two-Level SAS Name

Referencing Temporary SAS Files

To reference temporary SAS files, you can specify the default libref Work, a period, and the data set name. For example, the two-level name, Work.Test, references the SAS data set named Test that is stored in the temporary SAS library Work.
Figure 2.4 Two-Level Temporary SAS Library Name
Two-Level Temporary SAS Library Work.Test
Alternatively, you can use a one-level name (the data set name only) to reference a file in a temporary SAS library. When you specify a one-level name, the default libref Work is assumed. For example, the one-level name Test references the SAS data set named Test that is stored in the temporary SAS library Work.
Figure 2.5 One-Level Temporary SAS Library Name
One-Level Temporary SAS Library Test

Rules for SAS Names

By default, the following rules apply to the names of SAS data sets, variables, and libraries:
  • They must begin with a letter (A-Z, either uppercase or lowercase) or an underscore (_).
  • They can continue with any combination of numbers, letters, or underscores.
  • They can be 1 to 32 characters long.
  • SAS library names (librefs) can be 1 to 8 characters long.
These are examples of valid data set names and variable names:
  • Payroll
  • LABDATA2015_2018
  • _EstimatedTaxPayments3

VALIDVARNAME=System Option

SAS has various rules for variable names. You set these rules using the VALIDVARNAME= system option. VALIDVARNAME specifies the rules for valid SAS variable names that can be created and processed during a SAS session.
Syntax, VALIDVARNAME=
VALIDVARNAME= V7|UPCASE|ANY
V7 specifies that variable names must follow these rules:
  • SAS variable names can be up to 32 characters long.
  • The first character must begin with a letter of the Latin alphabet (A - Z, either uppercase or lowercase) or an underscore (_). Subsequent characters can be letters of the Latin alphabet, numerals, or underscores.
  • Trailing blanks are ignored. The variable name alignment is left-justified.
  • A variable name cannot contain blanks or special characters except for an underscore.
  • A variable name can contain mixed-case letters. SAS stores and writes the variable name in the same case that is used in the first reference to the variable. However, when SAS processes a variable name, SAS internally converts it to uppercase. Therefore, you cannot use the same variable name with a different combination of uppercase and lowercase letters to represent different variables. For example, cat, Cat, and CAT all represent the same variable.
  • Do not assign variables the names of special SAS automatic variables (such as _N_ and _ERROR_) or variable list names (such as _NUMERIC_, _CHARACTER_, and _ALL_) to variables.
UPCASE specifies that the variable name follows the same rules as V7, except that the variable name is uppercase, as in earlier versions of SAS.
ANY specifies that SAS variable names must follow these rules:
  • The name can begin with or contain any characters, including blanks, national characters, special characters, and multi-byte characters.
  • The name can be up to 32 bytes long.
  • The name cannot contain any null bytes.
  • Leading blanks are preserved, but trailing blanks are ignored.
  • The name must contain at least one character. A name with all blanks is not permitted.
  • A variable name can contain mixed-case letters. SAS stores and writes the variable name in the same case that is used in the first reference to the variable. However, when SAS processes a variable name, SAS internally converts it to uppercase. Therefore, you cannot use the same variable name with a different combination of uppercase and lowercase letters to represent different variables. For example, cat, Cat, and CAT all represent the same variable.
Note: If you use characters other than the ones that are valid when VALIDVARNAME=V7, then you must express the variable name as a name literal and set VALIDVARNAME=ANY. If the name includes either a percent sign (%) or an ampersand (&), then use single quotation marks in the name literal to avoid interaction with the SAS macro facility.
CAUTION:
Throughout SAS, using the name literal syntax with SAS member names that exceed the 32-byte limit or have excessive embedded quotation marks might cause unexpected results.
The VALIDVARNAME=ANY system option enables compatibility with other DBMS variable (column) naming conventions, such as allowing embedded blanks and national characters.

VALIDMEMNAME=System Option

You can use the VALIDMEMNAME= system option to specify rules for naming SAS data sets.
Syntax, VALIDMEMNAME=
VALIDMEMNAME= COMPATIBLE | EXTEND
Important: COMPATIBLE is the default system option for VALIDMEMNAME=.
COMPATIBLE specifies that a SAS data set name must follow these rules:
  • The length of the names can be up to 32 characters long.
  • Names must begin with a letter of the Latin alphabet (A- Z, a - z) or an underscore. Subsequent characters can be letters of the Latin alphabet, numerals, or underscores.
  • Names cannot contain blanks or special characters except for an underscore
  • Names can contain mixed-case letters. SAS internally converts the member name to uppercase. Therefore, you cannot use the same member name with a different combination of uppercase and lowercase letters to represent different variables. For example, customer, Customer, and CUSTOMER all represent the same member name. How the name is saved on disk is determined by the operating environment.
EXTEND specifies that the data set name must follow these rules:
  • Names can include national characters.
  • The name can include special characters, except for the / * ? " < > |: - characters.
  • The name must contain at least one character.
  • The length of the name can be up to 32 bytes.
  • Null bytes are not allowed.
  • Names cannot begin with a blank or a ‘.’ ( period).
  • Leading and trailing blanks are deleted when the member is created.
  • Names can contain mixed-case letters. SAS internally converts the member name to uppercase. Therefore, you cannot use the same member name with a different combination of uppercase and lowercase letters to represent different variables. For example, customer, Customer, and CUSTOMER all represent the same member name. How the name appears is determined by the operating environment.
Note: If VALIDMEMNAME=EXTEND, SAS data set names must be written as a SAS name literal. If you use either a percent sign (%) or an ampersand (&), then you must use single quotation marks in the name literal in order to avoid interaction with the SAS macro facility.
CAUTION:
Throughout SAS, using the name literal syntax with SAS member names that exceed the 32-byte limit or that have excessive embedded quotation marks might cause unexpected results.
The intent of the VALIDMEMNAME=EXTEND system option is to enable compatibility with other DBMS member naming conventions, such as allowing embedded blanks and national characters.

When to Use VALIDMEMNAME=System Option

Use VALIDMEMNAME= EXTEND system option when the characters in a SAS data set name contains one of the following:
  • international characters
  • characters supported by third-party databases
  • characters that are commonly used in a filename
Last updated: August 23, 2018
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.148.105