@sasjs/utils 2.48.2 → 2.49.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/fs/generateCompileProgram.d.ts +1 -0
  2. package/fs/generateCompileProgram.js +154 -0
  3. package/fs/generateCompileProgram.js.map +1 -0
  4. package/fs/hash.d.ts +22 -0
  5. package/fs/hash.js +225 -0
  6. package/fs/hash.js.map +1 -0
  7. package/fs/index.d.ts +3 -0
  8. package/fs/index.js +13 -0
  9. package/fs/index.js.map +1 -0
  10. package/fs/internal/helper.d.ts +4 -0
  11. package/fs/internal/helper.js +125 -0
  12. package/fs/internal/helper.js.map +1 -0
  13. package/fs/sync.d.ts +6 -0
  14. package/fs/sync.js +208 -0
  15. package/fs/sync.js.map +1 -0
  16. package/index.d.ts +1 -0
  17. package/index.js +1 -0
  18. package/index.js.map +1 -1
  19. package/macros/mf_abort.sas +27 -0
  20. package/macros/mf_dedup.sas +53 -0
  21. package/macros/mf_deletefile.sas +31 -0
  22. package/macros/mf_existds.sas +30 -0
  23. package/macros/mf_existfeature.sas +59 -0
  24. package/macros/mf_existfileref.sas +33 -0
  25. package/macros/mf_existfunction.sas +37 -0
  26. package/macros/mf_existvar.sas +39 -0
  27. package/macros/mf_existvarlist.sas +56 -0
  28. package/macros/mf_fmtdttm.sas +42 -0
  29. package/macros/mf_getapploc.sas +78 -0
  30. package/macros/mf_getattrc.sas +34 -0
  31. package/macros/mf_getattrn.sas +34 -0
  32. package/macros/mf_getengine.sas +54 -0
  33. package/macros/mf_getfilesize.sas +64 -0
  34. package/macros/mf_getfmtlist.sas +61 -0
  35. package/macros/mf_getfmtname.sas +44 -0
  36. package/macros/mf_getkeyvalue.sas +32 -0
  37. package/macros/mf_getplatform.sas +75 -0
  38. package/macros/mf_getquotedstr.sas +57 -0
  39. package/macros/mf_getschema.sas +43 -0
  40. package/macros/mf_getuniquefileref.sas +60 -0
  41. package/macros/mf_getuniquelibref.sas +57 -0
  42. package/macros/mf_getuniquename.sas +22 -0
  43. package/macros/mf_getuser.sas +44 -0
  44. package/macros/mf_getvalue.sas +36 -0
  45. package/macros/mf_getvarcount.sas +49 -0
  46. package/macros/mf_getvarformat.sas +72 -0
  47. package/macros/mf_getvarlen.sas +56 -0
  48. package/macros/mf_getvarlist.sas +74 -0
  49. package/macros/mf_getvarnum.sas +58 -0
  50. package/macros/mf_getvartype.sas +52 -0
  51. package/macros/mf_getxengine.sas +43 -0
  52. package/macros/mf_increment.sas +29 -0
  53. package/macros/mf_isblank.sas +27 -0
  54. package/macros/mf_isdir.sas +34 -0
  55. package/macros/mf_isint.sas +36 -0
  56. package/macros/mf_islibds.sas +40 -0
  57. package/macros/mf_loc.sas +29 -0
  58. package/macros/mf_mkdir.sas +67 -0
  59. package/macros/mf_mval.sas +19 -0
  60. package/macros/mf_nobs.sas +26 -0
  61. package/macros/mf_trimstr.sas +50 -0
  62. package/macros/mf_uid.sas +21 -0
  63. package/macros/mf_verifymacvars.sas +72 -0
  64. package/macros/mf_wordsinstr1andstr2.sas +53 -0
  65. package/macros/mf_wordsinstr1butnotstr2.sas +54 -0
  66. package/macros/mf_writefile.sas +67 -0
  67. package/macros/mp_abort.sas +301 -0
  68. package/macros/mp_appendfile.sas +57 -0
  69. package/macros/mp_applyformats.sas +181 -0
  70. package/macros/mp_assert.sas +56 -0
  71. package/macros/mp_assertcols.sas +145 -0
  72. package/macros/mp_assertcolvals.sas +168 -0
  73. package/macros/mp_assertdsobs.sas +121 -0
  74. package/macros/mp_assertscope.sas +147 -0
  75. package/macros/mp_base64copy.sas +117 -0
  76. package/macros/mp_binarycopy.sas +79 -0
  77. package/macros/mp_chop.sas +194 -0
  78. package/macros/mp_cleancsv.sas +78 -0
  79. package/macros/mp_cntlout.sas +85 -0
  80. package/macros/mp_copyfolder.sas +84 -0
  81. package/macros/mp_coretable.sas +73 -0
  82. package/macros/mp_createconstraints.sas +70 -0
  83. package/macros/mp_createwebservice.sas +32 -0
  84. package/macros/mp_csv2ds.sas +140 -0
  85. package/macros/mp_deleteconstraints.sas +52 -0
  86. package/macros/mp_deletefolder.sas +70 -0
  87. package/macros/mp_dictionary.sas +52 -0
  88. package/macros/mp_dirlist.sas +263 -0
  89. package/macros/mp_distinctfmtvalues.sas +50 -0
  90. package/macros/mp_dropmembers.sas +46 -0
  91. package/macros/mp_ds2cards.sas +291 -0
  92. package/macros/mp_ds2csv.sas +212 -0
  93. package/macros/mp_ds2ddl.sas +30 -0
  94. package/macros/mp_ds2fmtds.sas +105 -0
  95. package/macros/mp_ds2inserts.sas +180 -0
  96. package/macros/mp_ds2md.sas +103 -0
  97. package/macros/mp_ds2squeeze.sas +120 -0
  98. package/macros/mp_dsmeta.sas +110 -0
  99. package/macros/mp_filtercheck.sas +251 -0
  100. package/macros/mp_filtergenerate.sas +105 -0
  101. package/macros/mp_filterstore.sas +254 -0
  102. package/macros/mp_filtervalidate.sas +105 -0
  103. package/macros/mp_getcols.sas +67 -0
  104. package/macros/mp_getconstraints.sas +115 -0
  105. package/macros/mp_getdbml.sas +335 -0
  106. package/macros/mp_getddl.sas +400 -0
  107. package/macros/mp_getformats.sas +124 -0
  108. package/macros/mp_getmaxvarlengths.sas +130 -0
  109. package/macros/mp_getpk.sas +281 -0
  110. package/macros/mp_gsubfile.sas +58 -0
  111. package/macros/mp_guesspk.sas +332 -0
  112. package/macros/mp_hashdataset.sas +91 -0
  113. package/macros/mp_hashdirectory.sas +162 -0
  114. package/macros/mp_include.sas +106 -0
  115. package/macros/mp_init.sas +76 -0
  116. package/macros/mp_jsonout.sas +406 -0
  117. package/macros/mp_lib2cards.sas +78 -0
  118. package/macros/mp_lib2inserts.sas +77 -0
  119. package/macros/mp_loadformat.sas +303 -0
  120. package/macros/mp_lockanytable.sas +243 -0
  121. package/macros/mp_lockfilecheck.sas +103 -0
  122. package/macros/mp_makedata.sas +107 -0
  123. package/macros/mp_md5.sas +58 -0
  124. package/macros/mp_perflog.sas +43 -0
  125. package/macros/mp_prevobs.sas +88 -0
  126. package/macros/mp_recursivejoin.sas +90 -0
  127. package/macros/mp_replace.sas +151 -0
  128. package/macros/mp_reseterror.sas +27 -0
  129. package/macros/mp_resetoption.sas +39 -0
  130. package/macros/mp_retainedkey.sas +247 -0
  131. package/macros/mp_runddl.sas +49 -0
  132. package/macros/mp_searchcols.sas +103 -0
  133. package/macros/mp_searchdata.sas +131 -0
  134. package/macros/mp_setkeyvalue.sas +55 -0
  135. package/macros/mp_sortinplace.sas +122 -0
  136. package/macros/mp_stackdiffs.sas +592 -0
  137. package/macros/mp_storediffs.sas +230 -0
  138. package/macros/mp_stprequests.sas +74 -0
  139. package/macros/mp_streamfile.sas +212 -0
  140. package/macros/mp_testjob.sas +92 -0
  141. package/macros/mp_testservice.sas +39 -0
  142. package/macros/mp_testwritespeedlibrary.sas +59 -0
  143. package/macros/mp_tree.sas +71 -0
  144. package/macros/mp_unzip.sas +90 -0
  145. package/macros/mp_updatevarlength.sas +93 -0
  146. package/macros/mp_validatecol.sas +97 -0
  147. package/macros/mp_wait4file.sas +35 -0
  148. package/macros/mp_webin.sas +59 -0
  149. package/macros/mp_zip.sas +85 -0
  150. package/package.json +5 -2
  151. package/scripts/copySASjsCore.ts +36 -0
  152. package/types/hash.d.ts +9 -0
  153. package/types/hash.js +3 -0
  154. package/types/hash.js.map +1 -0
  155. package/types/index.d.ts +1 -0
  156. package/types/index.js +1 -0
  157. package/types/index.js.map +1 -1
  158. package/utils/index.d.ts +1 -1
  159. package/utils/index.js +2 -1
  160. package/utils/index.js.map +1 -1
  161. package/utils/utils.d.ts +1 -0
  162. package/utils/utils.js +7 -1
  163. package/utils/utils.js.map +1 -1
@@ -0,0 +1,180 @@
1
+ /**
2
+ @file
3
+ @brief Export a dataset to SQL insert statements
4
+ @details Converts dataset values to SQL insert statements for use across
5
+ multiple database types.
6
+
7
+ Usage:
8
+
9
+ %mp_ds2inserts(sashelp.class,outref=myref,outds=class)
10
+ data class;
11
+ set sashelp.class;
12
+ stop;
13
+ proc sql;
14
+ %inc myref;
15
+
16
+ @param [in] ds The dataset to be exported
17
+ @param [in] maxobs= (max) The max number of inserts to create
18
+ @param [out] outref= (0) The output fileref. If it does not exist, it is
19
+ created. If it does exist, new records are APPENDED.
20
+ @param [out] schema= (0) The library (or schema) in which the target table is
21
+ located. If not provided, is ignored.
22
+ @param [out] outds= (0) The output table to load. If not provided, will
23
+ default to the table in the &ds parameter.
24
+ @param [in] flavour= (SAS) The SQL flavour to be applied to the output. Valid
25
+ options:
26
+ @li SAS (default) - suitable for regular proc sql
27
+ @li PGSQL - Used for Postgres databases
28
+ @param [in] applydttm= (YES) If YES, any columns using datetime formats will
29
+ be converted to native DB datetime literals
30
+
31
+ <h4> SAS Macros </h4>
32
+ @li mf_existfileref.sas
33
+ @li mf_getvarcount.sas
34
+ @li mf_getvarformat.sas
35
+ @li mf_getvarlist.sas
36
+ @li mf_getvartype.sas
37
+
38
+ @version 9.2
39
+ @author Allan Bowe (credit mjsq)
40
+ **/
41
+
42
+ %macro mp_ds2inserts(ds, outref=0,schema=0,outds=0,flavour=SAS,maxobs=max
43
+ ,applydttm=YES
44
+ )/*/STORE SOURCE*/;
45
+
46
+ %if not %sysfunc(exist(&ds)) %then %do;
47
+ %put %str(WAR)NING: &ds does not exist;
48
+ %return;
49
+ %end;
50
+
51
+ %if not %sysfunc(exist(&ds)) %then %do;
52
+ %put %str(WAR)NING: &ds does not exist;
53
+ %return;
54
+ %end;
55
+
56
+ %if %index(&ds,.)=0 %then %let ds=WORK.&ds;
57
+
58
+ %let flavour=%upcase(&flavour);
59
+ %if &flavour ne SAS and &flavour ne PGSQL %then %do;
60
+ %put %str(WAR)NING: &flavour is not supported;
61
+ %return;
62
+ %end;
63
+
64
+ %if &outref=0 %then %do;
65
+ %put %str(WAR)NING: Please provide a fileref;
66
+ %return;
67
+ %end;
68
+ %if %mf_existfileref(&outref)=0 %then %do;
69
+ filename &outref temp lrecl=66000;
70
+ %end;
71
+
72
+ %if &schema=0 %then %let schema=;
73
+ %else %let schema=&schema..;
74
+
75
+ %if &outds=0 %then %let outds=%scan(&ds,2,.);
76
+
77
+ %local nobs;
78
+ proc sql noprint;
79
+ select count(*) into: nobs TRIMMED from &ds;
80
+ %if &nobs=0 %then %do;
81
+ data _null_;
82
+ file &outref mod;
83
+ put "/* No rows found in &ds */";
84
+ run;
85
+ %end;
86
+
87
+ %local vars;
88
+ %let vars=%mf_getvarcount(&ds);
89
+ %if &vars=0 %then %do;
90
+ data _null_;
91
+ file &outref mod;
92
+ put "/* No columns found in &schema.&ds */";
93
+ run;
94
+ %return;
95
+ %end;
96
+ %else %if &vars>1600 and &flavour=PGSQL %then %do;
97
+ data _null_;
98
+ file &fref mod;
99
+ put "/* &schema.&ds contains &vars vars */";
100
+ put "/* Postgres cannot handle tables with over 1600 vars */";
101
+ put "/* No inserts will be generated for this table */";
102
+ run;
103
+ %return;
104
+ %end;
105
+
106
+ %local varlist varlistcomma;
107
+ %let varlist=%mf_getvarlist(&ds);
108
+ %let varlistcomma=%mf_getvarlist(&ds,dlm=%str(,),quote=double);
109
+
110
+ /* next, export data */
111
+ data _null_;
112
+ file &outref mod ;
113
+ if _n_=1 then put "/* &schema.&outds (&nobs rows, &vars columns) */";
114
+ set &ds;
115
+ %if &maxobs ne max %then %do;
116
+ if _n_>&maxobs then stop;
117
+ %end;
118
+ length _____str $32767;
119
+ call missing(_____str);
120
+ format _numeric_ best.;
121
+ format _character_ ;
122
+ %local i comma var vtype vfmt;
123
+ %do i=1 %to %sysfunc(countw(&varlist));
124
+ %let var=%scan(&varlist,&i);
125
+ %let vtype=%mf_getvartype(&ds,&var);
126
+ %let vfmt=%upcase(%mf_getvarformat(&ds,&var,force=1));
127
+ %if &i=1 %then %do;
128
+ %if &flavour=SAS %then %do;
129
+ put "insert into &schema.&outds set ";
130
+ put " &var="@;
131
+ %end;
132
+ %else %if &flavour=PGSQL %then %do;
133
+ _____str=cats(
134
+ "INSERT INTO &schema.&outds ("
135
+ ,symget('varlistcomma')
136
+ ,") VALUES ("
137
+ );
138
+ put _____str;
139
+ put " "@;
140
+ %end;
141
+ %end;
142
+ %else %do;
143
+ %if &flavour=SAS %then %do;
144
+ put " ,&var="@;
145
+ %end;
146
+ %else %if &flavour=PGSQL %then %do;
147
+ put " ,"@;
148
+ %end;
149
+ %end;
150
+ %if &vtype=N %then %do;
151
+ %if &flavour=SAS %then %do;
152
+ put &var;
153
+ %end;
154
+ %else %if &flavour=PGSQL %then %do;
155
+ if missing(&var) then put 'NULL';
156
+ %if &applydttm=YES and "%substr(&vfmt.xxxxxxxx,1,8)"="DATETIME"
157
+ %then %do;
158
+ else put "TIMESTAMP '" &var E8601DT25.6 "'";
159
+ %end;
160
+ %else %do;
161
+ else put &var;
162
+ %end;
163
+ %end;
164
+ %end;
165
+ %else %do;
166
+ _____str="'"!!trim(tranwrd(&var,"'","''"))!!"'";
167
+ put _____str;
168
+ %end;
169
+ %end;
170
+ %if &flavour=SAS %then %do;
171
+ put ';';
172
+ %end;
173
+ %else %if &flavour=PGSQL %then %do;
174
+ put ');';
175
+ %end;
176
+
177
+ if _n_=&nobs then put /;
178
+ run;
179
+
180
+ %mend mp_ds2inserts;
@@ -0,0 +1,103 @@
1
+ /**
2
+ @file
3
+ @brief Create a Markdown Table from a dataset
4
+ @details A markdown table is a simple table representation for use in
5
+ documents written in markdown format.
6
+
7
+ An online generator is available here:
8
+ https://www.tablesgenerator.com/markdown_tables
9
+
10
+ This structure is also used by the Macro Core library for documenting input/
11
+ output datasets, as well as the sasjs/cli tool for documenting inputs/outputs
12
+ for web services.
13
+
14
+ We take the standard definition one step further by embedding the informat
15
+ in the table header row, like so:
16
+
17
+ |var1:$32|var2:best.|var3:date9.|
18
+ |---|---|---|
19
+ |some text|42|01JAN1960|
20
+ |blah|1|31DEC1999|
21
+
22
+ Which resolves to:
23
+
24
+ |var1:$32|var2:best.|var3:date9.|
25
+ |---|---|---|
26
+ |some text|42|01JAN1960|
27
+ |blah|1|31DEC1999|
28
+
29
+
30
+ Usage:
31
+
32
+ %mp_ds2md(sashelp.class)
33
+
34
+ @param [in] libds the library / dataset to create or read from.
35
+ @param [out] outref= (mdtable) Fileref to contain the markdown
36
+ @param [out] showlog= (YES) Set to NO to avoid printing markdown to the log
37
+
38
+ <h4> SAS Macros </h4>
39
+ @li mf_getvarlist.sas
40
+ @li mf_getvarformat.sas
41
+
42
+ @version 9.3
43
+ @author Allan Bowe
44
+ **/
45
+
46
+ %macro mp_ds2md(
47
+ libds,
48
+ outref=mdtable,
49
+ showlog=YES
50
+ )/*/STORE SOURCE*/;
51
+
52
+ /* check fileref is assigned */
53
+ %if %sysfunc(fileref(&outref)) > 0 %then %do;
54
+ filename &outref temp;
55
+ %end;
56
+
57
+ %local vars;
58
+ %let vars=%upcase(%mf_getvarlist(&libds));
59
+
60
+ %if %trim(X&vars)=X %then %do;
61
+ %put &sysmacroname: Table &libds has no columns!!;
62
+ %return;
63
+ %end;
64
+
65
+ /* create the header row */
66
+ data _null_;
67
+ file &outref;
68
+ length line $32767;
69
+ call missing(line);
70
+ put '|'
71
+ %local i var fmt;
72
+ %do i=1 %to %sysfunc(countw(&vars));
73
+ %let var=%scan(&vars,&i);
74
+ %let fmt=%lowcase(%mf_getvarformat(&libds,&var,force=1));
75
+ "&var:&fmt|"
76
+ %end;
77
+ ;
78
+ put '|'
79
+ %do i=1 %to %sysfunc(countw(&vars));
80
+ "---|"
81
+ %end;
82
+ ;
83
+ run;
84
+
85
+ /* write out the data */
86
+ data _null_;
87
+ file &outref mod dlm='|' lrecl=32767;
88
+ set &libds ;
89
+ length line $32767;
90
+ line='|`'!!cats(%mf_getvarlist(&libds,dlm=%str(%)!!' `|`'!!cats%()))!!' `|';
91
+ put line;
92
+ run;
93
+
94
+ %if %upcase(&showlog)=YES %then %do;
95
+ options ps=max lrecl=max;
96
+ data _null_;
97
+ infile &outref;
98
+ input;
99
+ putlog _infile_;
100
+ run;
101
+ %end;
102
+
103
+ %mend mp_ds2md;
@@ -0,0 +1,120 @@
1
+ /**
2
+ @file
3
+ @brief Create a smaller version of a dataset, without data loss
4
+ @details This macro will scan the input dataset and create a new one, that
5
+ has the minimum variable lengths needed to store the data without data loss.
6
+
7
+ Inspiration was taken from [How to Reduce the Disk Space Required by a
8
+ SAS® Data Set](https://www.lexjansen.com/nesug/nesug06/io/io18.pdf) by
9
+ Selvaratnam Sridharma. The end of the referenced paper presents a macro named
10
+ "squeeze", hence the nomenclature.
11
+
12
+ Usage:
13
+
14
+ data big;
15
+ length my big $32000;
16
+ do i=1 to 1e4;
17
+ my=repeat('oh my',100);
18
+ big='dawg';
19
+ special=._;
20
+ output;
21
+ end;
22
+ run;
23
+
24
+ %mp_ds2squeeze(work.big,outds=work.smaller)
25
+
26
+ The following will also be printed to the log (exact values may differ
27
+ depending on your OS and COMPRESS settings):
28
+
29
+ > MP_DS2SQUEEZE: work.big was 625MB
30
+
31
+ > MP_DS2SQUEEZE: work.smaller is 5MB
32
+
33
+ @param [in] libds The library.dataset to be squeezed
34
+ @param [out] outds= (work.mp_ds2squeeze) The squeezed dataset to create
35
+ @param [in] mdebug= (0) Set to 1 to enable DEBUG messages
36
+
37
+ <h4> SAS Macros </h4>
38
+ @li mf_getfilesize.sas
39
+ @li mf_getuniquefileref.sas
40
+ @li mf_getuniquename.sas
41
+ @li mp_getmaxvarlengths.sas
42
+
43
+ <h4> Related Programs </h4>
44
+ @li mp_ds2squeeze.test.sas
45
+
46
+ @version 9.3
47
+ @author Allan Bowe
48
+ **/
49
+
50
+ %macro mp_ds2squeeze(
51
+ libds,
52
+ outds=work.mp_ds2squeeze,
53
+ mdebug=0
54
+ )/*/STORE SOURCE*/;
55
+ %local dbg source;
56
+ %if &mdebug=1 %then %do;
57
+ %put &sysmacroname entry vars:;
58
+ %put _local_;
59
+ %end;
60
+ %else %do;
61
+ %let dbg=*;
62
+ %let source=/source2;
63
+ %end;
64
+
65
+ %local optval ds fref startsize;
66
+ %let ds=%mf_getuniquename();
67
+ %let fref=%mf_getuniquefileref();
68
+ %let startsize=%mf_getfilesize(libds=&libds,format=yes);
69
+
70
+ %mp_getmaxvarlengths(&libds,outds=&ds)
71
+
72
+ data _null_;
73
+ set &ds end=last;
74
+ file &fref;
75
+ /* grab the types */
76
+ retain dsid;
77
+ if _n_=1 then dsid=open("&libds",'is');
78
+ if dsid le 0 then do;
79
+ msg=sysmsg();
80
+ put msg=;
81
+ stop;
82
+ end;
83
+ type=vartype(dsid,varnum(dsid, name));
84
+ if last then rc=close(dsid);
85
+ /* write out the length statement */
86
+ if _n_=1 then put 'length ';
87
+ length len $6;
88
+ if type='C' then do;
89
+ if maxlen=0 then len='$1';
90
+ else len=cats('$',maxlen);
91
+ end;
92
+ else do;
93
+ if maxlen=0 then len='3';
94
+ else len=cats(maxlen);
95
+ end;
96
+ put ' ' name ' ' len;
97
+ if last then put ';';
98
+ run;
99
+
100
+ /* configure varlenchk - as we are explicitly shortening the variables */
101
+ %let optval=%sysfunc(getoption(varlenchk));
102
+ options varlenchk=NOWARN;
103
+
104
+ data &outds;
105
+ %inc &fref &source;
106
+ set &libds;
107
+ run;
108
+
109
+ options varlenchk=&optval;
110
+
111
+ %if &mdebug=0 %then %do;
112
+ proc sql;
113
+ drop table &ds;
114
+ filename &fref clear;
115
+ %end;
116
+
117
+ %put &sysmacroname: &libds was &startsize;
118
+ %put &sysmacroname: &outds is %mf_getfilesize(libds=&outds,format=yes);
119
+
120
+ %mend mp_ds2squeeze;
@@ -0,0 +1,110 @@
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 libds The library.dataset to export the metadata for
53
+ @param 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_getddl.sas
60
+ @li mp_getformats.sas
61
+ @li mp_getpk.sas
62
+ @li mp_guesspk.sas
63
+
64
+ **/
65
+
66
+ %macro mp_dsmeta(libds,outds=work.dsmeta);
67
+
68
+ %local ds1 ds2;
69
+ data;run; %let ds1=&syslast;
70
+ data;run; %let ds2=&syslast;
71
+
72
+ /* setup the ODS capture */
73
+ ods output attributes=&ds1 enginehost=&ds2;
74
+
75
+ /* export the metadata */
76
+ proc contents data=&libds;
77
+ run;
78
+
79
+ /* load it into a single table */
80
+ data &outds (keep=ods_table name value);
81
+ length ods_table $10 name label2 label1 label $100
82
+ value cvalue cvalue1 cvalue2 $1000
83
+ nvalue nvalue1 nvalue2 8;
84
+ if _n_=1 then call missing (of _all_);
85
+ * putlog (_all_)(=);
86
+ set &ds1 (in=atrs) &ds2 (in=eng);
87
+ if atrs then do;
88
+ ods_table='ATTRIBUTES';
89
+ name=coalescec(label1,label);
90
+ value=coalescec(cvalue1,cvalue,put(coalesce(nvalue1,nvalue),best.));
91
+ output;
92
+ if label2 ne '' then do;
93
+ name=label2;
94
+ value=coalescec(cvalue2,put(nvalue2,best.));
95
+ output;
96
+ end;
97
+ end;
98
+ else if eng then do;
99
+ ods_table='ENGINEHOST';
100
+ name=coalescec(label1,label);
101
+ value=coalescec(cvalue1,cvalue,put(coalesce(nvalue1,nvalue),best.));
102
+ output;
103
+ end;
104
+ run;
105
+
106
+ proc sql;
107
+ drop table &ds1, &ds2;
108
+
109
+ %mend mp_dsmeta;
110
+