Some procedures, such as PROC REG, automatically display labels if they exist. In other procedures, an option is available which displays variable labels. For instance, the LABEL option in PROC PRINT displays variable labels instead of variable names. In PROC LOGISTIC, the PARMLABEL option adds a Label column in the ParameterEstimates table showing variable labels in place of variable names in each model effect.
But for some tables, such as the ParameterEstimates tables produced by the GLM and GENMOD procedures, no labeling option is available and only variable names can be shown. One way to display more descriptive variable labels instead of names is to make use of name literals. A name literal allows you to use special characters (such as blanks) that are not allowed in SAS variable names. See "SAS Name Literals" and "Avoiding Errors When Using Name Literals" in SAS Language Reference: Concepts. The system option VALIDVARNAME=ANY must also be specified to allow the nonstandard variable names.
Illustrated below are three ways to create and use label-named variables. The first requires you to enter labels while the remaining two make use of variable labels which are already assigned to variables.
The following examples use the data set WHEEZE containing repeated measures data from the "Six Cities" study of the health effects of air pollution (Ware et al. 1984). The data analyzed are the 16 selected cases in Lipsitz, Fitzmaurice, et al. (1994). The binary response is the wheezing status of 16 children at ages 9, 10, 11, and 12 years. A logistic regression model will be fit using city of residence and age as explanatory variables. See reference citations in the GENMOD procedure documentation.
data wheeze; input case city $ age smoke wheeze @@; label age="age of subject" city="subject's city:" smoke="mother smokes"; datalines; 1 portage 9 0 1 1 portage 10 0 1 1 portage 11 0 1 1 portage 12 0 0 2 kingston 9 1 1 2 kingston 10 2 1 2 kingston 11 2 0 2 kingston 12 2 0 3 kingston 9 0 1 3 kingston 10 0 0 3 kingston 11 1 0 3 kingston 12 1 0 4 portage 9 0 0 4 portage 10 0 1 4 portage 11 0 1 4 portage 12 1 0 5 kingston 9 0 0 5 kingston 10 1 0 5 kingston 11 1 0 5 kingston 12 1 0 6 portage 9 0 0 6 portage 10 1 0 6 portage 11 1 0 6 portage 12 1 0 7 kingston 9 1 0 7 kingston 10 1 0 7 kingston 11 0 0 7 kingston 12 0 0 8 portage 9 1 0 8 portage 10 1 0 8 portage 11 1 0 8 portage 12 2 0 9 portage 9 2 1 9 portage 10 2 0 9 portage 11 1 0 9 portage 12 1 0 10 kingston 9 0 0 10 kingston 10 0 0 10 kingston 11 0 0 10 kingston 12 1 0 11 kingston 9 1 1 11 kingston 10 0 0 11 kingston 11 0 1 11 kingston 12 0 1 12 portage 9 1 0 12 portage 10 0 0 12 portage 11 0 0 12 portage 12 0 0 13 kingston 9 1 0 13 kingston 10 0 1 13 kingston 11 1 1 13 kingston 12 1 1 14 portage 9 1 0 14 portage 10 2 0 14 portage 11 1 0 14 portage 12 2 1 15 kingston 9 1 0 15 kingston 10 1 0 15 kingston 11 1 0 15 kingston 12 2 1 16 portage 9 1 1 16 portage 10 1 1 16 portage 11 2 0 16 portage 12 1 0 ;
The following DATA step adds copies of the AGE and CITY variables to the WHEEZE data set. The variable copies are named using name literals containing descriptive labels. A name literal has the form "some text"n
and may contain characters such as blanks which are not normally allowed in SAS variable names. Note that the VALIDVARNAME=ANY option is used so that nonstandard SAS names can be used. Although this option removes some restrictions on variable names, the maximum length of a name is still restricted to 32 characters. Once the new variables are created, you can use them in place of the original variables as shown in the PROC GENMOD step which fits the logistic model. After the analysis, you can set the VALIDVARNAME=V7 option to once again require standard SAS names for variables.
options validvarname=any; data wheeze; set wheeze; "age of subject"n=age; "subject's city:"n=city; run; proc genmod data=wheeze; class case "subject's city:"n; model wheeze = "subject's city:"n "age of subject"n / dist=binomial; repeated subject=case; run;
Notice the use of the new labels in the Parameter column of the GEE Parameter Estimates table produced by PROC GENMOD:
|
In procedures like GLM, GENMOD, and others, the ParameterEstimates table limits the width of the column containing the variable names to 20 characters by default. If you have interaction or nested effects in your model which result in combinations of variable names, then you will need to use the NAMELEN= option in the PROC statement to increase the allowable length of names in this column, usually up to a maximum of 200 characters.
If your data set already has labels assigned to the variables, you can create a copy of a variable and name the copy using the label of the original variable. The first DATA step below uses the VLABEL function to retrieve the label of the AGE variable. The NLITERAL function creates a name literal from the label and the CALL SYMPUT statement stores it in a macro variable. Note that the macro variable has the same name as the original variable. The LENGTH statement restricts the label in the name literal to 32 characters so that it will be a valid SAS variable name. The second DATA step uses the macro variable to create a new variable that is a copy of AGE. In this way, the copy of AGE has the label "age of subject" as its name. You can then use the new label-named copy as in the GENMOD step above. Note that the system option VALIDVARNAME=ANY must be in effect in order to use the data set containing the label-named copies.
data _null_; set wheeze; length agelbl $ 32; agelbl=vlabel(age); call symput("age",nliteral(agelbl)); stop; run; options validvarname=any; data wheeze; set wheeze; &age = age; run;
Now you can have the AGE variable's label appear instead of its name by adding an ampersand to the beginning of the variable name in your code. For example, the following statements will cause the label for AGE to appear instead of its name, AGE, throughout the PROC LOGISTIC results. Notice that the code is identical to what you would normally specify except that an ampersand appears before AGE. This references the AGE macro variable instead of the AGE data set variable resulting in the label-named variable being used.
proc logistic data=wheeze; strata case; model wheeze = &age; run;
You can do this for additional variables in your data set by adding more assignment and CALL SYMPUT statement pairs in the first DATA step and more assignment statements in the second DATA step. The intermediate label variables should also be added in the LENGTH statement. Alternatively, you can create label-named copies of all variables in your data set as described next.
The following macro, NameToLabel, creates label-named copies of all variables in the DATA= data set. If a variable has no label, no copy is created. If you want the macro to create a new data set containing the original and label-named copies, specify the OUT= option. Otherwise, the macro simply adds the label-named copies to the DATA= data set. Macro variables, with names identical to the original data set variables, are also created to simplify referring to the label-named variables in subsequent code. If a variable has no label, its macro variable contains the variable name.
To define the NameToLabel macro and make it available for use, submit the following statements unchanged.
%macro NameToLabel(data=, out=); %if &out= %then %let out=&data; proc contents noprint data=&data out=__vars; run; options validvarname=any; data _null_; set __vars end=eof; if _n_ = 1 then call execute("data &out; set &data;"); if label ne "" then do; label = nliteral(substr(label, 1, 32)); call execute(trim(label) || '=' || trim(name) || ';'); call symput(name,trim(label)); end; else call symput(name,trim(name)); if eof then call execute("run;"); %mend;
The following macro call runs the NameToLabel macro on the WHEEZE data set above, creates label-named copies of all variables in the data set that have labels, adds the copies to data set WHEEZE, and creates macro variables with the same names as the data set variables. While a RUN statement is usually not required to execute a macro, it is required when running the NameToLabel macro.
%NameToLabel(data=wheeze); run;
Below are the variables in data set WHEEZE as displayed by PROC CONTENTS:
|
After running the macro, specifying the macro variable names instead of the data set variable names in subsequent procedure steps results in variable labels appearing in place of variable names. The system option VALIDVARNAME=ANY must be in effect. The NameToLabel macro sets VALIDVARNAME=ANY and it remains in effect after the macro finishes. Set the VALIDVARNAME=V7 option to once again require standard SAS names for variables.
The results of the following GENMOD analysis display the labels of the variables CITY, AGE, and SMOKE since they had labels assigned. For the variables without labels, WHEEZE and CASE, the variable names are shown.
proc genmod data=wheeze; class &case &city; model &wheeze = &city &age &smoke / dist=binomial; repeated subject=&case; run;
|
Product Family | Product | System | SAS Release | |
Reported | Fixed* | |||
SAS System | SAS/STAT | Microsoft Windows XP Professional | ||
Microsoft Windows Server 2008 | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 95/98 | ||||
OS/2 | ||||
Microsoft® Windows® for x64 | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
OpenVMS VAX | ||||
z/OS | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX | ||||
SAS System | SAS/ETS | z/OS | ||
OpenVMS VAX | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft® Windows® for x64 | ||||
OS/2 | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows XP Professional | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX | ||||
SAS System | SAS/QC | z/OS | ||
OpenVMS VAX | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft® Windows® for x64 | ||||
OS/2 | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows XP Professional | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX | ||||
SAS System | SAS/OR | z/OS | ||
OpenVMS VAX | ||||
Microsoft® Windows® for 64-Bit Itanium-based Systems | ||||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | ||||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | ||||
Microsoft Windows XP 64-bit Edition | ||||
Microsoft® Windows® for x64 | ||||
OS/2 | ||||
Microsoft Windows 95/98 | ||||
Microsoft Windows 2000 Advanced Server | ||||
Microsoft Windows 2000 Datacenter Server | ||||
Microsoft Windows 2000 Server | ||||
Microsoft Windows 2000 Professional | ||||
Microsoft Windows NT Workstation | ||||
Microsoft Windows Server 2003 Datacenter Edition | ||||
Microsoft Windows Server 2003 Enterprise Edition | ||||
Microsoft Windows Server 2003 Standard Edition | ||||
Microsoft Windows Server 2008 | ||||
Microsoft Windows XP Professional | ||||
Windows Millennium Edition (Me) | ||||
Windows Vista | ||||
64-bit Enabled AIX | ||||
64-bit Enabled HP-UX | ||||
64-bit Enabled Solaris | ||||
ABI+ for Intel Architecture | ||||
AIX | ||||
HP-UX | ||||
HP-UX IPF | ||||
IRIX | ||||
Linux | ||||
Linux for x64 | ||||
Linux on Itanium | ||||
OpenVMS Alpha | ||||
OpenVMS on HP Integrity | ||||
Solaris | ||||
Solaris for x64 | ||||
Tru64 UNIX |
Type: | Usage Note |
Priority: |
Date Modified: | 2009-05-29 14:56:27 |
Date Created: | 2009-05-19 15:04:56 |