BookmarkSubscribeRSS Feed
ChrisNZ
Tourmaline | Level 20
Hi Cynthia,

Replacing
put _ALL_;
with
put (_ALL_)(:);

will drop all variables declared after the put statement, including _N_and _ERROR_ .
Cynthia_sas
SAS Super FREQ
Hi:
I must not understand what you mean. When I replaced PUT _ALL_; with PUT (_ALL_) (:); this is what I expected and what I got:
[pre]
What will be written out?
"Africa" "Boot" "Addis Ababa" 12 29761 191821 769
"Africa" "Men's Casual" "Addis Ababa" 4 67242 118036 2284
"Africa" "Men's Dress" "Addis Ababa" 7 76793 136273 2433
"Africa" "Sandal" "Addis Ababa" 10 62819 204284 1861
"Africa" "Slipper" "Addis Ababa" 14 68641 279795 1771
[/pre]

Actually, I did -not- expect to see _N_ and _ERROR_ in the previous posting's output (the first time with the simple PUT _ALL_) because I thought those were only written to the LOG and not to an external file. When I added the dlm=',' option to the FILE statement, then this is what I got (again, without _N_ and _ERROR_ which don't belong in the file anyway, in my opinion):
[pre]
What will be written out? with dlm?
"Africa","Boot","Addis Ababa",12,29761,191821,769
"Africa","Men's Casual","Addis Ababa",4,67242,118036,2284
"Africa","Men's Dress","Addis Ababa",7,76793,136273,2433
"Africa","Sandal","Addis Ababa",10,62819,204284,1861
"Africa","Slipper","Addis Ababa",14,68641,279795,1771
[/pre]

Is your argument with _N_ and _ERROR_ not being in the output file?

cynthia
ChrisNZ
Tourmaline | Level 20
>Is your argument with _N_ and _ERROR_ not being in the output file?
Not only, variable AAA is not output either.
Move the retain statement above the put statement and AAA will be output.

data _null_;
set sashelp.shoes(obs=5);
file 'c:\temp\test_putall.txt';
format _CHARACTER_ $quote.;
format _NUMERIC_;
if _N_ = 1 then link firstrow;
put (_ALL_)(:);
retain AAA 'kkk';
return;
firstrow:
put 'What will be written out?';
return;
run;
ChrisNZ
Tourmaline | Level 20
Just pushing this one a last time to the forefront in hope of knowing why some PDV variables are not exported, and why the position of the retain statement matters here.
Andre
Obsidian | Level 7
Chris and Cynthia,

Indeed i was first surprise about this as aaa is existing in the pdv
the only difference of functionning is about the sequentionnal position of the retain statement : before or after the external put statement using the _ALL_

Is ther some secondary buffer existing for the tabular print generated by a put
and different from the pdv?
and filled or not following certain reasons?

to show this difference i used two different put in an ods datastep context!

in one case aaa is empty in the other it is filled!
so the _ALL_ has a special functionning in regard gathering information
depending theit context of use!

[pre]
data _null_;
put _all_;
set sashelp.shoes(obs=5);
file 'c:\temp\test_putall.txt';
format _CHARACTER_ $quote.;
format _NUMERIC_;
put (_ALL_)(:);
retain AAA 25;
run;
data _null_;
put _all_;
set sashelp.shoes(obs=5);
file 'c:\temp\test_putOK.txt';
format _CHARACTER_ $quote.;
format _NUMERIC_;
retain AAA 25;
put (_ALL_)(:);
run;
ods pdf file="c:\temp\odsput.pdf";
data _null_;
putlog _all_;
set sashelp.shoes(obs=5);
file print ods=(var=(_all_));
format _CHARACTER_ $quote.;
format _NUMERIC_;
put (_ALL_)(:);
retain AAA 25;
run;
ods pdf close;



ods pdf file="c:\temp\put_ods_.pdf";
data _null_;
putlog _all_;
set sashelp.shoes(obs=5);
file print ods=(var=(_all_));
format _CHARACTER_ $quote.;
format _NUMERIC_;
put (_ALL_)(:) _ODS_ ;
retain AAA 25;
run;
ods pdf close;
[/pre]

BUT Chris this is documented on

http://support.sas.com/documentation/cdl/en/lrdict/61724/HTML/default/a000214163.htm

If you specify _ALL_, _CHAR_, or _NUMERIC_, only the variables that are defined before the RETAIN statement are affected.

HTH
Andre
ChrisNZ
Tourmaline | Level 20
Thanks for digging into this Andre.

It is not only the retain statement variables that are affected, any variable is.

Replace the retain statement with
AAA = . ;
or
length AAA 3;

and AAA will put output or not depending on its position in the code.
data_null__
Jade | Level 19
Hi Chris,

I glad you liked the data step enough want to use it. Sorry I did not see the question regarding PUT _ALL_; vs PUT (_ALL_)(:); sooner.

I think the question has been answered but I will give you my "explanation". Hopefully it wont be more confusing or wrong.

PUT _ALL_; is a special put statement specification. DUMP the PDV, including _ERROR_ and _N_ and the first and last dot variables and any others I forgot to mention. As far as I know the destination is not important, i.e. FILE LOG or FILE other.

The location is not important as PUT _ALL_; in this context means everything in the PDV.

_ALL_ is also a specification for a SAS Variable List. When used in PUT the parenthesis distinguish the two different functions, very subtle you must admit. I believe the thread has a reference to this powerful SAS feature. SAS Variable Lists are a key feature of dynamic programming.

When used in a data step put (_ALL_)() list is ,all the variables defined when the _ALL_ is encountered as the data step is being compiled. Placement of RETAIN or any other statements that define variables is important to determine which variables are included in the (_ALL_) list.

PUT (_ALL_)(:); can produce different results when used in different locations within a data step. PUT _ALL_; always puts variables in the PDV.

[pre]
15 data _null_;
16 put 'NOTE: LIST ' (_all_)(:);
17 put 'NOTE- PDV ' _all_;
18 set sashelp.class;
19 put 'NOTE: LIST ' (_all_)(:);
20 put 'NOTE- PDV ' _all_;
21 stop;
22 run;

NOTE: LIST
PDV Name= Sex= Age=. Height=. Weight=. _ERROR_=0 _N_=1
NOTE: LIST Alfred M 14 69 112.5
PDV Name=Alfred Sex=M Age=14 Height=69 Weight=112.5 _ERROR_=0 _N_=1
NOTE: There were 1 observations read from the data set SASHELP.CLASS.
[/pre]

The way the (_ALL_) list is defined is why my data step uses the LINK statement so the helper variables do not become part of put (_ALL_)();

You can use PUT (_ALL_)(:) at various locations within a data step a way to "study" what variables are defined at a particular location. Could be useful perhaps.

Let me know if you have other questions.
ChrisNZ
Tourmaline | Level 20
I suspected something along these lines as the parentheses make the behaviour of put change, but I have never heard of SAS Variable List before.

Everything falls into place now.

Thank you for these very clear explanations.
data_null__
Jade | Level 19
> but I have never heard of SAS Variable List before.

I'll bet you have used Numbered Range Lists (aka enumerated lists) and possibly the Name Range List, but you may not have seen this section of the documentation.

http://tinyurl.com/mtumkg
http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a000695105.htm

As I mentioned using these list can be a powerful SAS programming tool.

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 24 replies
  • 5064 views
  • 0 likes
  • 6 in conversation