Loading...
Searching...
No Matches
mpe_getlabels.sas
Go to the documentation of this file.
1/**
2 @file mpe_getlabels.sas
3 @brief Gets the table and column labels for a particular table
4 @details Builds a labels dataset by combining three inputs:
5
6 @li NAME - taken from `source`. This is typically a WORK subset of
7 the underlying table (e.g. after column-level security has been
8 applied) and dictates which columns appear in the output.
9 @li MEMLABEL / LABEL - taken from `tgt_ds` (the two-part
10 libref.dataset). This ensures the "true" table and column
11 labels are used rather than any that may have been stripped
12 during WORK subsetting.
13 @li DD_SHORTDESC / DD_LONGDESC - taken from `mpe_datadictionary`
14 where DD_SOURCE contains the `LIB.DSN` reference and DD_TYPE is
15 `COLUMN`.
16
17 If `tgt_ds` is not supplied it defaults to `source`.
18
19 @param [in] type The type of labels to fetch (only COLUMNS is
20 currently supported).
21 @param [in] source The dataset from which column NAMES are read.
22 @param [in] tgt_ds= (&source) The two-part libref.dataset from which
23 the table/column LABELS are read, and used when joining to
24 `mpe_datadictionary` for short/long descriptions.
25 @param [out] outds= (mpe_getlabels) The output dataset with columns
26 `name`, `memlabel`, `desc`, `longdesc`.
27
28 <h4> SAS Macros </h4>
29 @li mf_getuniquename.sas
30
31 @version 9.2
32 @author 4GL Apps Ltd
33 @copyright 4GL Apps Ltd. This code may only be used within Data Controller
34 and may not be re-distributed or re-sold without the express permission of
35 4GL Apps Ltd.
36**/
37
38%macro mpe_getlabels(type,source,tgt_ds=,outds=mpe_getlabels);
39%local src_cols tgt_cols;
40
41%if %superq(tgt_ds)= %then %let tgt_ds=&source;
42
43%if &type=COLUMNS %then %do;
44 %let src_cols=%mf_getuniquename();
45 %let tgt_cols=%mf_getuniquename();
46
47 /* NAMES from the (potentially filtered) source dataset */
48 proc contents noprint data=&source
49 out=&src_cols(keep=name);
50 run;
51
52 /* LABELS from the underlying target dataset */
53 proc contents noprint data=&tgt_ds
54 out=&tgt_cols(keep=name memlabel label);
55 run;
56
57 proc sql;
58 create table &outds as
59 select upcase(a.name) as name
60 ,b.memlabel
61 ,coalesce(c.dd_shortdesc,b.label) as desc
62 ,c.dd_longdesc as longdesc
63 from &src_cols a
64 inner join &tgt_cols b
65 on upcase(a.name)=upcase(b.name)
66 left join &mpelib..mpe_datadictionary
67 (where=(&dc_dttmtfmt. < tx_to
68 and dd_source ? %upcase("&tgt_ds")
69 and dd_type='COLUMN')) c
70 on scan(c.dd_source,-1,'.')=upcase(a.name);
71 quit;
72%end;
73
74%mend mpe_getlabels;