BookmarkSubscribeRSS Feed

PUT Statement with _ALL_

Started ‎07-06-2018 by
Modified ‎07-24-2019 by
Views 17,403

There are two distinct specifications which can be included in a PUT statement using the same token, _ALL_.

One _ALL_ is strictly a feature of the PUT statement. According to the documentation: it "writes the values of all variables, which includes automatic variables, that are defined in the current DATA step by using named output."

 

The other _ALL_ is usable in many SAS contexts. It is documented in SAS Language Reference: Concepts, which states that it "specifies all variables that are currently defined in the current DATA step."

 

Here is an example of the PUT-specific _ALL_:

data _null_;
file log column = cpos;
a =10;
b =20;
put   _all_   ;
c =30;
run;

The result is:

cpos=1 a=10 b=20 c=. _ERROR_=0 _N_=1

Now, how can we try the other _ALL_ if it is specified by the same 5 characters? It turns out that if we code a parentheses container in a PUT statement, SAS will interpret its contents as a variable list (see SAS Language Reference: Dictionary > Dictionary of Language Elements > Statements > PUT Statement, Formatted > (variable-list) ). But if we try

put   (_all_)   ;

we encounter a syntax error, because SAS expects a second parentheses container to follow immediately (see SAS Language Reference: Dictionary > Dictionary of Language Elements > Statements > PUT Statement, Formatted > (format-list) ). But if we try

put   (_all_) ( )   ;

we get a different syntax error, because SAS expects that second container to present some specifications for the PUT statement to apply. That requirement can be met with a do-nothing pointer control, as in

data _null_;
file log column = cpos;
a =10;
b =20;
put   (_all_)( +0 )   ;
c =30;
run;

The result is

10 20

That's not a very useful presentation if there are a lot of variables. Named output (automatic for the PUT statement's special _ALL_) is better. We can turn it on when using the special SAS name list _ALL_ by simply putting an equal sign in the format list, as in

data _null_;
file log column = cpos;
a =10;
b =20;
put   (_all_)( = )   ;
c =30;
run;

The result is

a=10 b=20

Now, how is this different from the result of the simple

put _all_;

First, the automatic variables _N_ and _ERROR_ and the system-maintained variable CPOS are excluded, by design. Second, the variable C is excluded because its first appearance is after the PUT statement. Special SAS name lists are processed at compile time, when they are replaced (internally) by lists of variables known at that time. Since C was not yet known, it is not included in the evaluated list. On the other hand, the _ALL_ which is implemented as a PUT statement feature operates at execution time and is therefore not sensitive to statement ordering.

 

This article was originally published by Howard Schreier on sasCommunity.org.

Comments

How do I drop the automated variables _ERROR_=0 _N_=1 being written to the output file

Version history
Last update:
‎07-24-2019 07:43 AM
Updated by:

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started

Article Labels
Article Tags