Sample 24843: Printing One Variable Per Line
Sometimes when a data set has a large number of variables, or has many
variables with long names or long character values, the output from
traditional column-oriented reporting tools such as PROC PRINT can be
difficult to use. When only a few records need to be printed, it
may be useful to produce a report that lists the name and value of each variable on a separate line. This can be done easily with DATA step code similar to the following:
DATA _NULL_;
SET MyLib.MyData;
FILE PRINT;
PUT _PAGE_; /* Start a new page for each record */
PUT (_ALL_) (= /);
RUN;
The key to this technique is the second PUT statement. _ALL_ is a special SAS variable list (like _NUMERIC_) that refers to all variables that are currently defined in the step. The second pair of parentheses encloses the format list that must accompany the variable list. The "=" serves as a format modifier that causes the output to be produced in named format -- that is, print the variable name followed by an equal sign and then the variable value. The "/" causes SAS to start a new line for each variable.
This differs from the more commonly seen PUT _ALL_ in two ways. First, PUT _ALL_ fits as many variables as it can onto one line before going to the next. This produces a more compact, but also more crowded, listing.
Second, the _ALL_ in PUT _ALL_ is a PUT statement keyword that causes the values of all variables in the program data vector to be printed, including automatic variables such as _N_ and _ERROR_. The sample program uses _ALL_ not as a PUT statement keyword but as a special variable list. Consequently, the automatic variables are not printed.
Of course, you can include other DATA step statements such as WHERE or DROP to limit the records or variables to be printed, or even to create new variables.
This technical tip was submitted by Mike Rhoads of Westat. If you have a SAS technical tip you think others would find helpful, please share it with us. Send your tips or topics you'd like to see covered to techeditor@sas.com.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
This samples shows how to use the DATA step to oroduce a report that lists the name and value of each variable on a separate line.
Type: | Sample |
Topic: | SAS Reference ==> DATA Step Non SAS Authors ==> Mike Rhoads
|
Date Modified: | 2005-12-10 03:02:51 |
Date Created: | 2004-10-19 11:48:41 |
Operating System and Release Information
SAS System | Base SAS | All | n/a | n/a |