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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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