BookmarkSubscribeRSS Feed
Black
Calcite | Level 5
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.
6 REPLIES 6
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
Ran your code. Did you notice the message below in your SASLOG?

NOTE: DATA STEP stopped due to looping.


Scott Barry
SBBWorks, Inc.
Black
Calcite | Level 5
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?
Black
Calcite | Level 5
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!
Olivier
Pyrite | Level 9
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
Black
Calcite | Level 5
Thank you, Olivier, you really got the point.
deleted_user
Not applicable
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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1119 views
  • 0 likes
  • 4 in conversation