ATTRIB Statement

Associates a format, informat, label, and length with one or more variables.
Valid in: DATA step
Category: Information
Type: Declarative
See: ATTRIB Statement under Windows, UNIX, and z/OS

Syntax

Arguments

variable-list(s)
names the variables that you want to associate with the attributes.
Tip:List the variables in any form that SAS allows.
attribute-list(s)
specifies one or more attributes to assign to variable-list. Specify one or more of these attributes in the ATTRIB statement:
FORMAT=format
associates a format with variables in variable-list.
Tip:The format can be either a standard SAS format or a format that is defined with the FORMAT procedure.
INFORMAT=informat
associates an informat with variables in variable-list.
Tip:The informat can be either a standard SAS informat or an informat that is defined with the FORMAT procedure.
LABEL='label'
associates a label with variables in variable-list.
LENGTH=<$>length
specifies the length of variables in variable-list.
Range:For character variables, the range is 1 to 32,767 bytes for all operating environments.
Restriction:You cannot change the length of a variable using LENGTH= from PROC DATASETS.
Requirement:Put a dollar sign ($) in front of the length of character variables.
Operating environment:For numeric variables, the minimum length that you can specify with the LENGTH= specification is 2 bytes in some operating environments and 3 bytes in others.
Tip:Use the ATTRIB statement before the SET statement to change the length of variables in an output data set when you use an existing data set as input.
TRANSCODE=YES | NO
specifies whether character variables can be transcoded. Use TRANSCODE=NO to suppress transcoding.
Default:YES
Restrictions:The TRANSCODE=NO attribute is not supported by some SAS Workspace Server clients. In SAS 9.2, if the attribute is not supported, variable values with TRANSCODE=NO are replaced (masked) with asterisks (*). Prior to SAS 9.2, variables with TRANSCODE=NO were transcoded.

Prior releases of SAS cannot access a SAS 9.1 data set that contains a variable with a TRANSCODE=NO attribute.

Transcode suppression is not supported by the V6TAPE engine.

Interactions:You can use the VTRANSCODE Function in SAS National Language Support (NLS): Reference Guide and VTRANSCODEX Function in SAS National Language Support (NLS): Reference Guide to return a value that indicates whether transcoding is on or off for a character variable.

If the TRANSCODE= attribute is set to NO for any character variable in a data set, then PROC CONTENTS prints a transcode column that contains the TRANSCODE= value for each variable in the data set. If all variables in the data set are set to the default TRANSCODE= value (YES), then no transcode column prints.

See:Transcoding for NLS in SAS National Language Support (NLS): Reference Guide

Details

The Basics

Using the ATTRIB statement in the DATA step permanently associates attributes with variables by changing the descriptor information of the SAS data set that contains the variables.
You can use ATTRIB in a PROC step, but the rules are different.

How SAS Treats Variables When You Assign Informats with the INFORMAT= Option in the ATTRIB Statement

Informats that are associated with variables by using the INFORMAT= option in the ATTRIB statement behave like informats that are used with modified list input. SAS reads the variables by using the scanning feature of list input, but applies the informat. In modified list input, SAS does the following:
  • does not use the value of w in an informat to specify column positions or input field widths in an external file
  • uses the value of w in an informat to specify the length of previously undefined character variables
  • ignores the value of w in numeric informats
  • uses the value of d in an informat in the same way it usually does for numeric informats
  • treats blanks that are embedded as input data as delimiters unless you change their status with the DLM= or DLMSTR= option specification in an INFILE statement
If you have coded the INPUT statement to use another style of input, such as formatted input or column input, that style of input is not used when you use the INFORMAT= option in the ATTRIB statement.

How SAS Treats Transcoded Variables When You Use the SET and MERGE Statements

When you use the SET or MERGE statement to create a data set from several data sets, SAS makes the TRANSCODE= attribute of the variable in the output data set equal to the TRANSCODE= value of the variable in the first data set. See Using the SET Statement with Transcoded Variables and Using the MERGE Statement with Transcoded Variables.
Note: The TRANSCODE= attribute is set when the variable is first seen on an input data set or in an ATTRIB TRANSCODE= statement. If a SET or MERGE statement comes before an ATTRIB TRANSCODE= statement and the TRANSCODE= attribute contradicts the SET statement, a warning will occur.

Comparisons

You can use either an ATTRIB statement or an individual attribute statement such as FORMAT, INFORMAT, LABEL, and LENGTH to change an attribute that is associated with a variable.

Examples

Example 1: Examples of ATTRIB Statements with Varying Numbers of Variables and Attributes

Here are examples of ATTRIB statements that contain different numbers of variables and attributes:
  • single variable and single attribute:
    attrib cost length=4;
  • single variable with multiple attributes:
    attrib saleday informat=mmddyy. 
    format=worddate.;
    
  • multiple variables with the same multiple attributes:
    attrib x y length=$4 label='TEST VARIABLE';
    
  • multiple variables with different multiple attributes:
    attrib x length=$4 label='TEST VARIABLE'
           y length=$2 label='RESPONSE';
    
  • variable list with single attribute:
    attrib month1-month12
           label='MONTHLY SALES';
    

Example 2: Using the SET Statement with Transcoded Variables

In this example, which uses the SET statement, the variable Z's TRANSCODE= attribute in data set A is NO because B is the first data set and Z's TRANSCODE= attribute in data set B is NO.
data b;
   length z $4;
   z = 'ice';
   attrib z transcode = no;
data c;
   length z $4;
   z = 'snow';
   attrib z transcode = yes;
data a;
   set b;
   set c;
   /* Check transcode setting for variable Z */
   rc1 = vtranscode(z);
   put rc1=;
run;

Example 3: Using the MERGE Statement with Transcoded Variables

In this example, which uses the MERGE statement, the variable Z's TRANSCODE= attribute in data set A is YES because C is the first data set and Z's TRANSCODE= attribute in data set C is YES.
data b;
   length z $4;
   z = 'ice';
   attrib z transcode = no;
data c;
   length z $4;
   z = 'snow';
   attrib z transcode = yes;
data a;
   merge c b;
   /* Check transcode setting for variable Z */
   rc1 = vtranscode(z);
   put rc1=;
run;

See Also

Functions:
VTRANSCODE Function in SAS National Language Support (NLS): Reference Guide
VTRANSCODEX Function in SAS National Language Support (NLS): Reference Guide