As the first step in the decommissioning of sasCommunity.org the site has been converted to read-only mode.


Here are some tips for How to share your SAS knowledge with your professional network.


Difference between revisions of "PUT Statement with ALL"

From sasCommunity
Jump to: navigation, search
m (Add some formatting, white space and some wiki links)
(migrated)
 
Line 1: Line 1:
 +
{{Template:Article_Migrated|https://communities.sas.com/t5/SAS-Communities-Library/PUT-Statement-with-ALL/ta-p/475999}}
 
There are two distinct specifications which can be included in a [[PUT statement]] using the '''same''' token, '''_ALL_'''.  
 
There are two distinct specifications which can be included in a [[PUT statement]] using the '''same''' token, '''_ALL_'''.  
  

Latest revision as of 15:33, 27 July 2018


As part of the decommissioning effort for sasCommunity.org this article/tip has been migrated to communities.sas.com.

The new home for this article/tip is PUT Statement with ALL (https://communities.sas.com/t5/SAS-Communities-Library/PUT-Statement-with-ALL/ta-p/475999)



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 and is documented in SAS Language Reference: Dictionary (Dictionary of Language Elements > Statements > PUT Statement > Arguments > specification(s) >_ALL_), which states that 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 (SAS System Concepts > SAS Variables > SAS Variable Lists > Special SAS Name Lists > _ALL_), 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.