ATTRIB Statement


Associates a format, informat, label, and/or length with one or more variables

Valid: in a DATA step

Category: Information

Type: Declarative

See: ATTRIB Statement in the documentation for your operating environment.

Syntax

ATTRIB variable-list(s) attribute-list(s) ;

Arguments

variable-list

  • names the variables that you want to associate with the attributes.

  • Tip: List the variables in any form that SAS allows.

attribute-list

  • 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.

    • Requirement: Put a dollar sign ($) in front of the length of character variables.

    • 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.

    • Range: For character variables, the range is 1 to 32,767 for all operating environments.

      • Operating Environment Information: For numeric variables, the minimum length you can specify with the LENGTH= specification is 2 in some operating environments and 3 in others.

    • Restriction: You cannot change the length of a variable using LENGTH= from PROC DATASETS.

  • TRANSCODE=YES NO

    • specifies whether character variables can be transcoded. Use TRANSCODE=NO to suppress transcoding. For more information about transcoding, see 'Transcoding' in SAS National Language Support (NLS): User's Guide .

    • Default: YES

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

    • Restriction: Transcode suppression is not supported by the V6TAPE engine.

    • Interaction: You can use the VTRANSCODE and VTRANSCODEX functions to return a value that indicates whether transcoding is on or off for a character variable.

    • Interaction: 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.

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 on the ATTRIB Statement Informats that are associated with variables by using the INFORMAT= option on 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 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 a DELIMITER = 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 on 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 Example 2 on page 1111 and Example 3 on page 1111.

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

  • 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= label='TEST VARIABLE'; 
  • multiple variables with different multiple attributes:

     attrib x length= label='TEST VARIABLE'         y length= 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 ;     z = 'ice';     attrib z transcode = no;  data c;     length z ;     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 ;     z = 'ice';     attrib z transcode = no;  data c;     length z ;     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

Statements:

  • 'FORMAT Statement' on page 1207

  • 'INFORMAT Statement' on page 1242

  • 'LABEL Statement' on page 1277

  • 'LENGTH Statement' on page 1281

Functions:

  • 'VTRANSCODE Function' on page 909

  • 'VTRANSCODEX Function' on page 909




SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
SAS 9.1 Language Reference Dictionary, Volumes 1, 2 and 3
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 704

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net