It will not search each and every library. Sashelp.vcolumn contains details about the sas session (i.e. library names and dataset names). So by specifying the dataset name you can easily find its corresponding library.
... View more
For your second question below code will return the library name of specific dataset. Proc sql; select distinct libname from sashelp.vcolumn where upcase(memname) = "DATASETS NAME"; Quit;
... View more