Macros for SAS Application Developers
https://github.com/sasjs/core
Loading...
Searching...
No Matches
mp_dsmeta.sas
Go to the documentation of this file.
1/**
2 @file
3 @brief Export dataset metadata to a single output table
4 @details Exports the dataset attributes and enginehost information, then
5 converts the datasets into a single output table in the following format:
6
7|ODS_TABLE:$10.|NAME:$100.|VALUE:$1000.|
8|---|---|---|
9|`ATTRIBUTES `|`Data Set Name `|`SASHELP.CLASS `|
10|`ATTRIBUTES `|`Observations `|`19 `|
11|`ATTRIBUTES `|`Member Type `|`DATA `|
12|`ATTRIBUTES `|`Variables `|`5 `|
13|`ATTRIBUTES `|`Engine `|`V9 `|
14|`ATTRIBUTES `|`Indexes `|`0 `|
15|`ATTRIBUTES `|`Created `|`06/08/2020 00:59:14 `|
16|`ATTRIBUTES `|`Observation Length `|`40 `|
17|`ATTRIBUTES `|`Last Modified `|`06/08/2020 00:59:14 `|
18|`ATTRIBUTES `|`Deleted Observations `|`0 `|
19|`ATTRIBUTES `|`Protection `|`. `|
20|`ATTRIBUTES `|`Compressed `|`NO `|
21|`ATTRIBUTES `|`Data Set Type `|`. `|
22|`ATTRIBUTES `|`Sorted `|`NO `|
23|`ATTRIBUTES `|`Label `|`Student Data `|
24|`ATTRIBUTES `|`Data Representation `|`SOLARIS_X86_64, LINUX_X86_64, ALPHA_TRU64, LINUX_IA64 `|
25|`ATTRIBUTES `|`Encoding `|`us-ascii ASCII (ANSI) `|
26|`ENGINEHOST `|`Data Set Page Size `|`65536 `|
27|`ENGINEHOST `|`Number of Data Set Pages `|`1 `|
28|`ENGINEHOST `|`First Data Page `|`1 `|
29|`ENGINEHOST `|`Max Obs per Page `|`1632 `|
30|`ENGINEHOST `|`Obs in First Data Page `|`19 `|
31|`ENGINEHOST `|`Number of Data Set Repairs `|`0 `|
32|`ENGINEHOST `|`Filename `|`/opt/sas/sas9/SASHome/SASFoundation/9.4/sashelp/class.sas7bdat `|
33|`ENGINEHOST `|`Release Created `|`9.0401M7 `|
34|`ENGINEHOST `|`Host Created `|`Linux `|
35|`ENGINEHOST `|`Inode Number `|`28314616 `|
36|`ENGINEHOST `|`Access Permission `|`rw-r--r-- `|
37|`ENGINEHOST `|`Owner Name `|`sas `|
38|`ENGINEHOST `|`File Size `|`128KB `|
39|`ENGINEHOST `|`File Size (bytes) `|`131072 `|
40
41 Example usage:
42
43 %mp_dsmeta(sashelp.class,outds=work.mymeta)
44 proc print data=work.mymeta;
45 run;
46
47 For more details on creating datasets from PROC CONTENTS check out this
48 excellent [paper](
49 https://support.sas.com/resources/papers/proceedings14/1549-2014.pdf) by
50 [Louise Hadden](https://www.linkedin.com/in/louisehadden/).
51
52 @param [in] libds The library.dataset to export the metadata for
53 @param [out] outds= (work.dsmeta) The output table to contain the metadata
54
55 <h4> Related Files </h4>
56 @li mp_dsmeta.test.sas
57 @li mp_getcols.sas
58 @li mp_getdbml.sas
59 @li mp_ds2ddl.sas
60 @li mp_getformats.sas
61 @li mp_getpk.sas
62 @li mp_guesspk.sas
63
64 @sasjslint {"maxLineLength": 95}
65**/
66
67%macro mp_dsmeta(libds,outds=work.dsmeta);
68
69%local ds1 ds2;
70data;run; %let ds1=&syslast;
71data;run; %let ds2=&syslast;
72
73/* setup the ODS capture */
74ods output attributes=&ds1 enginehost=&ds2;
75
76/* export the metadata */
77proc contents data=&libds;
78run;
79
80/* load it into a single table */
81data &outds (keep=ods_table name value);
82 length ods_table $10 name label2 label1 label $100
83 value cvalue cvalue1 cvalue2 $1000
84 nvalue nvalue1 nvalue2 8;
85 if _n_=1 then call missing (of _all_);
86 /*putlog (_all_)(=);*/
87 set &ds1 (in=atrs) &ds2 (in=eng);
88 if atrs then do;
89 ods_table='ATTRIBUTES';
90 name=coalescec(label1,label);
91 value=coalescec(cvalue1,cvalue,put(coalesce(nvalue1,nvalue),best.));
92 output;
93 if label2 ne '' then do;
94 name=label2;
95 value=coalescec(cvalue2,put(nvalue2,best.));
96 output;
97 end;
98 end;
99 else if eng then do;
100 ods_table='ENGINEHOST';
101 name=coalescec(label1,label);
102 value=coalescec(cvalue1,cvalue,put(coalesce(nvalue1,nvalue),best.));
103 output;
104 end;
105run;
106
107proc sql;
108drop table &ds1, &ds2;
109
110%mend mp_dsmeta;
111