DATA Step, Macro, Functions and more

A strange thing about getting numbers of all library's datasets.

Reply
Occasional Contributor
Posts: 13

A strange thing about getting numbers of all library's datasets.

I want to get the numbers of all libraries' datasets. I can use there kinds of ways, as following:
proc sql noprint;
select count(memname)
into :numwk1
from sashelp.vstable;
quit;
%put &numwk1; /*-------------------------------------=3677*/

data _null_;
set sashelp.vstable end=eof;
retain count 0;
count+1;
if eof then do;
call symput('numwk2',left(count));
end;
run;
%put &numwk2; /*--------------------------------------=3677*/

data _null_;
if 0 then set sashelp.vstable nobs=a;
call symput('numwk3',a);
run;
%put &numwk3; /*--------------------------=9.0071993E15*/

Why the third answer is different with others?

Thanks a million.
Super Contributor
Super Contributor
Posts: 3,174

Re: A strange thing about getting numbers of all library's datasets.

Ran your code. Did you notice the message below in your SASLOG?

NOTE: DATA STEP stopped due to looping.


Scott Barry
SBBWorks, Inc.
Occasional Contributor
Posts: 13

Re: A strange thing about getting numbers of all library's datasets.

Thank you very much for your reminding.
I don't know why there is a looping here?
If i use this code to a normal data set, it is ok.
How could this looping happen?
Occasional Contributor
Posts: 13

Re: A strange thing about getting numbers of all library's datasets.

If i change the code to this:
data _null_;
set sashelp.vstable nobs=a;
call symput('numwk3',a);
run;
%put &numwk3;
the result is still 9.0071E15.

very strange!
Super Contributor
Posts: 260

Re: A strange thing about getting numbers of all library's datasets.

This is not so trange when you think that VSTABLE is a view, not a dataset. Being so, it cannot have the number of observations stored in a "contents" part of the physical file. Hence the wrong value, which must stand for "infinity", I think. Other solutions really count the records, so they give the correct answer.

And just a tip : the SASHELP views are based on SQL views stored in a pseudo library called DICTIONARY. For efficiency sake, you'd better change the first solution to FROM DICTIONARY.TABLES ; to avoid using one view on a view. Unfortunately, in a Data step, you are compelled to use the SASHELP views, since the DICTIONARY views are only available in an SQL query.

Regards
Olivier
Occasional Contributor
Posts: 13

Re: A strange thing about getting numbers of all library's datasets.

Thank you, Olivier, you really got the point.
N/A
Posts: 0

Re: A strange thing about getting numbers of all library's datasets.

Black

why not use proc contents or proc datasets or sashelp.vtable?

Of course a view does not store a count of the information it will provide when executed, but otherwise dictionary.tables surfaced as sashelp.vtable is very informative....
... so why do you want new code to provide this information ... ?

PeterC
Ask a Question
Discussion stats
  • 6 replies
  • 180 views
  • 0 likes
  • 4 in conversation