Statements |
Valid: | in a DATA step |
Category: | Information |
Type: | Declarative |
See: | ATTRIB Statement under Windows UNIX OpenVMS z/OS |
Syntax |
ATTRIB variable-list(s) attribute-list(s) ; |
names the variables that you want to associate with the attributes.
Tip: | List the variables in any form that SAS allows. |
specifies one or more attributes to assign to variable-list. Specify one or more of these attributes in the ATTRIB statement:
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. |
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. |
specifies the length of variables in variable-list.
specifies whether character variables can be transcoded. Use TRANSCODE=NO to suppress transcoding. For more information about transcoding, see Transcoding in the SAS National Language Support (NLS): Reference Guide.
Details |
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.
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 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
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.
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 |
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';
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;
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 |
| |||||||||
|
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.