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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 6 replies
  • 1077 views
  • 0 likes
  • 4 in conversation