Data is obtained by querying the SAS system table `dictionary.tables`, which provides metadata about all tables registered in the SAS environment. This is an internal source of information within the SAS system and not external data or data created by the user directly in this script.
1 Code Block
SAS Macro
Explanation : This block marks the beginning of the macro's execution and definition. It announces the macro call and initializes the global macro variable `_dslist_` as empty. It contains the logic to assign a default value to the `libref` parameter if it is not provided (using the 'user' or 'work' system option) and ensures that the `libref` is in uppercase.
%IF not %LENGTH(&libref) %THEN %let libref=%sysfunc(getoption(user));
7
%IF not %LENGTH(&libref) %THEN %let libref=work;
8
%let libref=%upcase(&libref);
2 Code Block
PROC SQL
Explanation : This segment uses `PROC SQL` in silent mode (`noprint`) to query the `dictionary.tables` metadata table. It selects all distinct member names (`memname`) that are of type 'DATA' and belong to the library specified by `&libref`. The retrieved names are stored in the macro variable `_dslist_`, with a conditional separator: either a space, or `&libref..` if the `prefix` parameter is active.
Copied!
proc sql noprint;
select distinct memname into :_dslist_ separated by
%if %length(&prefix) %then %do;
" &libref.."
%end;
%else %do;
' '
%end;
from dictionary.tables
where memtype='DATA'
and libname="&libref";
quit;
1
PROC SQL noprint;
2
select distinct memname into :_dslist_ separated BY
3
%IF %LENGTH(&prefix) %THEN %DO;
4
" &libref.."
5
%END;
6
%ELSE %DO;
7
' '
8
%END;
9
from dictionary.tables
10
where memtype='DATA'
11
and LIBNAME="&libref";
12
QUIT;
3 Code Block
SAS Macro
Explanation : This final block adjusts the `_dslist_` macro variable if `prefix` was used, because the 'separated by' in `PROC SQL` only applies between elements, not to the first one. It terminates `PROC SQL` with `run;` and concludes the definition of the `dslist` macro with `%mend`.
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : This is public domain software. No guarantee as to suitability or accuracy is given or implied. User uses this code entirely at their own risk.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.