Published on :
Reporting CREATION_INTERNE

Variable Metadata Report

This code is also available in: Deutsch Español Français
Awaiting validation
This SAS© macro, `MetaShort`, takes the name of a SAS© library (`lib`) as a parameter. If no library name is provided, it uses the value of the macro variable `&pname`. It starts by defining a custom format to display variable types ('Char' for character, 'Num' for numeric). Then, it uses `PROC DATASETS` to collect metadata for all data tables in the specified library and stores them in a temporary table named `WORK.TEMP`. A `PROC SQL` query is then executed to retrieve the physical path of the library from `DICTIONARY.MEMBERS`. The report is generated in HTML5 (`meta.html`) in this physical path via `PROC REPORT`, using the `WORK.TEMP` table. The report displays the dataset name, variable name, its type (formatted), its length, its format, its informat, and its label. An empty line is inserted between variable groups for each dataset to improve readability. Finally, ODS destinations are closed and reset.
Data Analysis

Type : CREATION_INTERNE


The source data for the report is generated internally by `PROC DATASETS` which extracts metadata from the tables in the user-specified library. `DICTIONARY.MEMBERS` is a SAS system view used to retrieve the library path.

1 Code Block
Macro
Explanation :
Definition of the `MetaShort` macro taking a `lib` parameter. If `lib` is empty, the macro variable `&pname` is used as the default value for the library.
Copied!
1%macro MetaShort(lib);
2%IF %superq(lib)= %THEN %let lib=&pname;
3 
2 Code Block
PROC FORMAT
Explanation :
Creates a custom `type.` format to display numeric values 1 and 2 as character strings ('Num' and 'Char'), representing variable types.
Copied!
1 PROC FORMAT;
2 value type 2="Char"
3 1 = "Num";
4 RUN;
3 Code Block
PROC DATASETS Data
Explanation :
Uses `PROC DATASETS` to extract metadata for all data tables (`memtype=data`) from the specified library (`&lib`). Content information is stored in the temporary table `WORK.TEMP`.
Copied!
1 PROC DATASETS library=&lib memtype=DATA ;
2 contents DATA=_all_ out=work.temp ;
3 RUN;
4 QUIT;
4 Code Block
PROC SQL
Explanation :
A `PROC SQL` query is executed to retrieve the physical path (`path`) of the library (`&lib`) from the `DICTIONARY.MEMBERS` system view. The path is stored in the `&libpath` macro variable and spaces are removed.
Copied!
1 PROC SQL noprint;
2 select path into: libpath
3 from Dictionary.members
4 where LIBNAME =upcase("&lib");
5 QUIT;
6 
7 %let libpath=%sysfunc(strip(&libpath));
5 Code Block
PROC REPORT
Explanation :
Prepares the ODS HTML5 destination to create a `meta.html` file in the library path. `PROC REPORT` uses the `WORK.TEMP` table to generate the report. It displays columns for the dataset name, variable name, its type (formatted), its length, its format, its informat, and its label. An empty line is added after each group of variables for a given dataset. ODS destinations are then closed and reset.
Copied!
1 title "Datasets in &lib";
2 odds html5 path="&libpath" (url="")
3 body="meta.html";
4 PROC REPORT DATA=work.temp headline headskip spacing=2 ;
5 columns memname name type LENGTH FORMAT informat label;
6 define memname /order order=DATA "Dataset" ;
7 define name /display "Variable";
8 define type /display FORMAT=type. "Type";
9 define LENGTH /display "Length";
10 define FORMAT /display "Format";
11 define informat /display "Informat";
12 define label /display "Label";
13 compute after memname;
14 line ' ';
15 endcomp;
16 RUN;
17 odds html5 close;
18 odds html;
19 title ;
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 : ************************************************************************* * MetaShort * report the metadata of variables in the given lib including name, type, * length, format, informat, and label * *************************************************************************