@sasjs/core 4.2.0 → 4.4.0

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.
package/README.md CHANGED
@@ -196,6 +196,8 @@ When contributing to this library, it is therefore important to ensure that all
196
196
  We are currently on major release v4. Breaking changes should be marked with the [deprecated](https://www.doxygen.nl/manual/commands.html#cmddeprecated) doxygen tag. The following changes are planned when the next major (breaking) release becomes necessary:
197
197
 
198
198
  * mp_testservice.sas to be renamed as mp_execute.sas (as it doesn't actually test anything)
199
+ * `insert_cmplib` option of mcf_xxx macros will be deprecated (the option is now checked automatically with value inserted only if needed)
200
+ * mcf_xxx macros to have `wrap=` option defaulted to YES for convenience
199
201
 
200
202
  ## Star Gazing
201
203
 
package/base/mp_abort.sas CHANGED
@@ -66,7 +66,10 @@
66
66
  %if %length(&mac)>0 %then %put NOTE- called by &mac;
67
67
  %put NOTE - &msg;
68
68
 
69
- %if %symexist(_SYSINCLUDEFILEDEVICE) %then %do;
69
+ %if %symexist(_SYSINCLUDEFILEDEVICE)
70
+ /* abort cancel FILE does not restart outside the INCLUDE on Viya 3.5 */
71
+ and "&SYSPROCESSNAME " ne "Compute Server "
72
+ %then %do;
70
73
  %if "*&_SYSINCLUDEFILEDEVICE*" ne "**" %then %do;
71
74
  data &errds;
72
75
  iftrue='1=1';
@@ -3,10 +3,28 @@
3
3
  @brief Export a dataset to a CSV file WITH leading blanks
4
4
  @details Export a dataset to a file or fileref, retaining leading blanks.
5
5
 
6
+ When using SASJS headerformat, the input statement is provided in the first
7
+ row of the CSV.
8
+
6
9
  Usage:
7
10
 
8
11
  %mp_ds2csv(sashelp.class,outref="%sysfunc(pathname(work))/file.csv")
9
12
 
13
+ filename example temp;
14
+ %mp_ds2csv(sashelp.air,outref=example,headerformat=SASJS)
15
+ data; infile example; input;put _infile_; if _n_>5 then stop;run;
16
+
17
+ data _null_;
18
+ infile example;
19
+ input;
20
+ call symputx('stmnt',_infile_);
21
+ stop;
22
+ run;
23
+ data work.want;
24
+ infile example dsd firstobs=2;
25
+ input &stmnt;
26
+ run;
27
+
10
28
  Why use mp_ds2csv over, say, proc export?
11
29
 
12
30
  1. Ability to retain leading blanks (this is a major one)
@@ -23,17 +41,24 @@
23
41
  @li LABEL - Use the variable label (or name, if blank)
24
42
  @li NAME - Use the variable name
25
43
  @li SASJS - Used to create sasjs-formatted input CSVs, eg for use in
26
- mp_testservice.sas
44
+ mp_testservice.sas. This format will supply an input statement in the
45
+ first row, making ingestion by datastep a breeze. Special misisng values
46
+ will be prefixed with a period (eg `.A`) to enable ingestion on both SAS 9
47
+ and Viya. Dates / Datetimes etc are identified by the format type (lookup
48
+ with mcf_getfmttype.sas) and converted to human readable formats (not
49
+ numbers).
27
50
  @param [out] outfile= The output filename - should be quoted.
28
51
  @param [out] outref= (0) The output fileref (takes precedence if provided)
29
- @param [in] outencoding= (0) The output encoding to use (unquoted)
52
+ @param [in] outencoding= (0) The (quoted) output encoding to use, eg `"UTF-8"`
30
53
  @param [in] termstr= (CRLF) The line seperator to use. For SASJS, will
31
54
  always be CRLF. Valid values:
32
55
  @li CRLF
33
56
  @li LF
34
57
 
35
58
  <h4> SAS Macros </h4>
59
+ @li mcf_getfmttype.sas
36
60
  @li mf_getuniquename.sas
61
+ @li mf_getvarformat.sas
37
62
  @li mf_getvarlist.sas
38
63
  @li mf_getvartype.sas
39
64
 
@@ -50,7 +75,7 @@
50
75
  ,termstr=CRLF
51
76
  )/*/STORE SOURCE*/;
52
77
 
53
- %local outloc delim i varlist var vcnt vat dsv vcom vmiss;
78
+ %local outloc delim i varlist var vcnt vat dsv vcom vmiss fmttype vfmt;
54
79
 
55
80
  %if not %sysfunc(exist(&ds)) %then %do;
56
81
  %put %str(WARN)ING: &ds does not exist;
@@ -60,7 +85,7 @@
60
85
  %if %index(&ds,.)=0 %then %let ds=WORK.&ds;
61
86
 
62
87
  %if &outencoding=0 %then %let outencoding=;
63
- %else %let outencoding=encoding="&outencoding";
88
+ %else %let outencoding=encoding=&outencoding;
64
89
 
65
90
  %if &outref=0 %then %let outloc=&outfile;
66
91
  %else %let outloc=&outref;
@@ -68,6 +93,7 @@
68
93
  %if &headerformat=SASJS %then %do;
69
94
  %let delim=",";
70
95
  %let termstr=CRLF;
96
+ %mcf_getfmttype(wrap=YES)
71
97
  %end;
72
98
  %else %if &dlm=COMMA %then %let delim=",";
73
99
  %else %let delim=";";
@@ -77,7 +103,8 @@
77
103
  /* first get headers */
78
104
  data _null_;
79
105
  file &outloc &outencoding lrecl=32767 termstr=&termstr;
80
- length header $ 2000 varnm $32 dlm $1;
106
+ length header $ 2000 varnm vfmt $32 dlm $1 fmttype $8;
107
+ call missing(of _all_);
81
108
  dsid=open("&ds.","i");
82
109
  num=attrn(dsid,"nvars");
83
110
  dlm=&delim;
@@ -92,7 +119,14 @@ data _null_;
92
119
  %end;
93
120
  %else %if &headerformat=SASJS %then %do;
94
121
  if vartype(dsid,i)='C' then header=cats(varnm,':$char',varlen(dsid,i),'.');
95
- else header=cats(varnm,':best.');
122
+ else do;
123
+ vfmt=coalescec(varfmt(dsid,i),'0');
124
+ fmttype=mcf_getfmttype(vfmt);
125
+ if fmttype='DATE' then header=cats(varnm,':date9.');
126
+ else if fmttype='DATETIME' then header=cats(varnm,':E8601DT26.6');
127
+ else if fmttype='TIME' then header=cats(varnm,':TIME12.');
128
+ else header=cats(varnm,':best.');
129
+ end;
96
130
  %end;
97
131
  %else %do;
98
132
  %put &sysmacroname: Invalid headerformat value (&headerformat);
@@ -147,14 +181,29 @@ data _null_;
147
181
  %let vcom=;
148
182
  %end;
149
183
  %if %mf_getvartype(&ds,&var)=N %then %do;
184
+ %if &headerformat = SASJS %then %do;
185
+ %let vcom=&delim;
186
+ %let fmttype=%sysfunc(mcf_getfmttype(%mf_getvarformat(&ds,&var)0));
187
+ %if &fmttype=DATE %then %let vfmt=DATE9.;
188
+ %else %if &fmttype=DATETIME %then %let vfmt=E8601DT26.6;
189
+ %else %if &fmttype=TIME %then %let vfmt=TIME12.;
190
+ %else %do;
191
+ %let vfmt=;
192
+ %let vcom=;
193
+ %end;
194
+ %end;
195
+ %else %let vcom=;
196
+
150
197
  /* must use period - in order to work in both 9.4 and Viya 3.5 */
151
198
  if missing(&var) and &var ne %sysfunc(getoption(MISSING)) then do;
152
199
  &vmiss=cats('.',&var);
153
200
  put &vmiss &vat;
154
201
  end;
155
- else put &var &vat;
202
+ else put &var &vfmt &vcom &vat;
203
+
156
204
  %end;
157
205
  %else %do;
206
+ %if &i ne &vcnt %then %let vcom=&delim;
158
207
  put &var &&vlen&i &vcom &vat;
159
208
  %end;
160
209
  %end;
@@ -96,8 +96,7 @@ filename &fref1 clear;
96
96
  run;
97
97
  %mp_abort(
98
98
  mac=&sysmacroname,
99
- msg=%str(Filter validation issues. ERR=%superq(SYSERRORTEXT)
100
- , WARN=%superq(SYSWARNINGTEXT) )
99
+ msg=%str(Filter validation issues.)
101
100
  )
102
101
  %end;
103
102
  %let syscc=1008;
@@ -51,9 +51,10 @@ https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/mcrolref/n1j5tcc0n2xczyn1
51
51
  this dataset.
52
52
  It will then run an abort cancel FILE to stop the include running, and pass
53
53
  the dataset back.
54
- NOTE - it is NOT possible to read this dataset as part of _this_ macro -
55
- when running abort cancel FILE, ALL macros are closed, so instead it is
56
- necessary to invoke "%mp_abort(mode=INCLUDE)" OUTSIDE of any macro wrappers.
54
+
55
+ IMPORTANT NOTE - it is NOT possible to read this dataset as part of _this_
56
+ macro! When running abort cancel FILE, ALL macros are closed, so instead it
57
+ is necessary to invoke "%mp_abort(mode=INCLUDE)" OUTSIDE of macro wrappers.
57
58
 
58
59
 
59
60
  @version 9.4
@@ -131,7 +131,7 @@
131
131
  %put &sysmacroname: Switching to DATASTEP engine;
132
132
  %goto datastep;
133
133
  %end;
134
- data &tempds /view=&tempds;set &ds;
134
+ data &tempds;set &ds;
135
135
  %if &fmt=N %then format _numeric_ best32.;;
136
136
  /* PRETTY is necessary to avoid line truncation in large files */
137
137
  proc json out=&jref pretty
@@ -182,7 +182,7 @@
182
182
  %end;
183
183
  other = [best.];
184
184
 
185
- data &tempds/view=&tempds;
185
+ data &tempds;
186
186
  attrib _all_ label='';
187
187
  %do i=1 %to &numcols;
188
188
  %if &&typelong&i=char or &fmt=Y %then %do;
@@ -244,8 +244,7 @@
244
244
  %end;
245
245
 
246
246
  proc sql;
247
- drop view &tempds;
248
- drop table &colinfo;
247
+ drop table &colinfo, &tempds;
249
248
 
250
249
  %if &showmeta=YES %then %do;
251
250
  data _null_; file &jref encoding='utf-8' mod;
@@ -85,7 +85,7 @@ run;
85
85
  /* do not proceed if no observations can be processed */
86
86
  %mp_abort(iftrue= (%sysfunc(getoption(OBS))=0)
87
87
  ,mac=&sysmacroname
88
- ,msg=%str(options obs = 0. syserrortext=&syserrortext)
88
+ ,msg=%str(cannot continue when options obs = 0)
89
89
  )
90
90
 
91
91
  %if &ACTION=LOCK %then %do;
@@ -12,17 +12,16 @@
12
12
 
13
13
  %mp_streamfile(contenttype=csv,inloc=/some/where.txt,outname=myfile.txt)
14
14
 
15
+ @param [in] contenttype= (TEXTS) Either TEXT, ZIP, CSV, EXCEL
16
+ @param [in] inloc= /path/to/file.ext to be sent
17
+ @param [in] inref= fileref of file to be sent (if provided, overrides `inloc`)
18
+ @param [out] outname= the name of the file, as downloaded by the browser
19
+
15
20
  <h4> SAS Macros </h4>
16
21
  @li mf_getplatform.sas
17
22
  @li mp_binarycopy.sas
18
23
 
19
- @param contenttype= Either TEXT, ZIP, CSV, EXCEL (default TEXT)
20
- @param inloc= /path/to/file.ext to be sent
21
- @param inref= fileref of file to be sent (if provided, overrides `inloc`)
22
- @param outname= the name of the file, as downloaded by the browser
23
-
24
24
  @author Allan Bowe
25
- @source https://github.com/sasjs/core
26
25
 
27
26
  **/
28
27
 
@@ -48,16 +47,16 @@ data _null_;
48
47
  if xengine='STREAM' then call symputx('streamweb',1,'l');
49
48
  run;
50
49
 
51
- %if &contentype=ZIP %then %do;
50
+ %if &contentype=CSV %then %do;
52
51
  %if &platform=SASMETA and &streamweb=1 %then %do;
53
52
  data _null_;
54
- rc=stpsrv_header('Content-type','application/zip');
53
+ rc=stpsrv_header('Content-type','application/csv');
55
54
  rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
56
55
  run;
57
56
  %end;
58
57
  %else %if &platform=SASVIYA %then %do;
59
- filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.zip'
60
- contenttype='application/zip'
58
+ filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.txt'
59
+ contenttype='application/csv'
61
60
  contentdisp="attachment; filename=&outname";
62
61
  %end;
63
62
  %end;
@@ -75,56 +74,67 @@ run;
75
74
  contentdisp="attachment; filename=&outname";
76
75
  %end;
77
76
  %end;
78
- %else %if &contentype=XLSX %then %do;
77
+ %else %if &contentype=HTML %then %do;
78
+ %if &platform=SASVIYA %then %do;
79
+ filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json"
80
+ contenttype="text/html";
81
+ %end;
82
+ %end;
83
+ %else %if &contentype=TEXT %then %do;
79
84
  %if &platform=SASMETA and &streamweb=1 %then %do;
80
85
  data _null_;
81
- rc=stpsrv_header('Content-type',
82
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
86
+ rc=stpsrv_header('Content-type','application/text');
83
87
  rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
84
88
  run;
85
89
  %end;
86
90
  %else %if &platform=SASVIYA %then %do;
87
- filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.xls'
88
- contenttype=
89
- 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
91
+ filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.txt'
92
+ contenttype='application/text'
90
93
  contentdisp="attachment; filename=&outname";
91
94
  %end;
92
95
  %end;
93
- %else %if &contentype=TEXT %then %do;
96
+ %else %do;
97
+ %put %str(ERR)OR: Content Type &contenttype NOT SUPPORTED by &sysmacroname!;
98
+ %return;
99
+ %end;
100
+ %else %if &contentype=WOFF %then %do;
94
101
  %if &platform=SASMETA and &streamweb=1 %then %do;
95
102
  data _null_;
96
- rc=stpsrv_header('Content-type','application/text');
97
- rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
103
+ rc=stpsrv_header('Content-type','font/woff');
98
104
  run;
99
105
  %end;
100
106
  %else %if &platform=SASVIYA %then %do;
101
- filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.txt'
102
- contenttype='application/text'
103
- contentdisp="attachment; filename=&outname";
107
+ filename _webout filesrvc parenturi="&SYS_JES_JOB_URI"
108
+ contenttype='font/woff';
104
109
  %end;
105
110
  %end;
106
- %else %if &contentype=CSV %then %do;
111
+ %else %if &contentype=XLSX %then %do;
107
112
  %if &platform=SASMETA and &streamweb=1 %then %do;
108
113
  data _null_;
109
- rc=stpsrv_header('Content-type','application/csv');
114
+ rc=stpsrv_header('Content-type',
115
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
110
116
  rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
111
117
  run;
112
118
  %end;
113
119
  %else %if &platform=SASVIYA %then %do;
114
- filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.txt'
115
- contenttype='application/csv'
120
+ filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.xls'
121
+ contenttype=
122
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
116
123
  contentdisp="attachment; filename=&outname";
117
124
  %end;
118
125
  %end;
119
- %else %if &contentype=HTML %then %do;
120
- %if &platform=SASVIYA %then %do;
121
- filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json"
122
- contenttype="text/html";
126
+ %else %if &contentype=ZIP %then %do;
127
+ %if &platform=SASMETA and &streamweb=1 %then %do;
128
+ data _null_;
129
+ rc=stpsrv_header('Content-type','application/zip');
130
+ rc=stpsrv_header('Content-disposition',"attachment; filename=&outname");
131
+ run;
132
+ %end;
133
+ %else %if &platform=SASVIYA %then %do;
134
+ filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name='_webout.zip'
135
+ contenttype='application/zip'
136
+ contentdisp="attachment; filename=&outname";
123
137
  %end;
124
- %end;
125
- %else %do;
126
- %put %str(ERR)OR: Content Type &contenttype NOT SUPPORTED by &sysmacroname!;
127
- %return;
128
138
  %end;
129
139
 
130
140
  %if &inref ne 0 %then %do;
@@ -0,0 +1,118 @@
1
+ /**
2
+ @file
3
+ @brief Returns the type of the format
4
+ @details
5
+ Returns the type, eg DATE / DATETIME / TIME (based on hard-coded lookup)
6
+ else CHAR / NUM.
7
+
8
+ This macro may be extended in the future to support custom formats - this
9
+ would necessitate a call to `dosubl()` for running a proc format with cntlout.
10
+
11
+ The function itself takes the following (positional) parameters:
12
+
13
+ | PARAMETER | DESCRIPTION |
14
+ |---|---|
15
+ |fmtnm| Format name to be tested. Can be with or without the w.d extension.|
16
+
17
+ Usage:
18
+
19
+ %mcf_getfmttype(wrap=YES, insert_cmplib=YES)
20
+
21
+ data _null_;
22
+ fmt1=mcf_getfmttype('DATE9.');
23
+ fmt2=mcf_getfmttype('DATETIME');
24
+ put (fmt:)(=);
25
+ run;
26
+ %put fmt3=%sysfunc(mcf_getfmttype(TIME9.));
27
+
28
+ Returns:
29
+
30
+ > fmt1=DATE fmt2=DATETIME
31
+ > fmt3=TIME
32
+
33
+ @param [out] wrap= (NO) Choose YES to add the proc fcmp wrapper.
34
+ @param [out] lib= (work) The output library in which to create the catalog.
35
+ @param [out] cat= (sasjs) The output catalog in which to create the package.
36
+ @param [out] pkg= (utils) The output package in which to create the function.
37
+ Uses a 3 part format: libref.catalog.package
38
+ @param [out] insert_cmplib= DEPRECATED - The CMPLIB option is checked and
39
+ values inserted only if needed.
40
+
41
+ <h4> SAS Macros </h4>
42
+ @li mcf_init.sas
43
+
44
+ <h4> Related Programs </h4>
45
+ @li mcf_getfmttype.test.sas
46
+ @li mp_init.sas
47
+
48
+ @todo "Custom Format Lookups" To enable site-specific formats, make
49
+ use of a set of SASJS_FMTLIST_(DATATYPE) global variables.
50
+
51
+ **/
52
+
53
+ %macro mcf_getfmttype(wrap=NO
54
+ ,insert_cmplib=DEPRECATED
55
+ ,lib=WORK
56
+ ,cat=SASJS
57
+ ,pkg=UTILS
58
+ )/*/STORE SOURCE*/;
59
+ %local i var cmpval found;
60
+
61
+ %if %mcf_init(mcf_getfmttype)=1 %then %return;
62
+
63
+ %if &wrap=YES %then %do;
64
+ proc fcmp outlib=&lib..&cat..&pkg;
65
+ %end;
66
+
67
+ function mcf_getfmttype(fmtnm $) $8;
68
+ if substr(fmtnm,1,1)='$' then return('CHAR');
69
+ else do;
70
+ /* extract NAME */
71
+ length fmt $32;
72
+ fmt=scan(fmtnm,1,'.');
73
+ do while (
74
+ substr(fmt,length(fmt),1) in ('1','2','3','4','5','6','7','8','9','0')
75
+ );
76
+ if length(fmt)=1 then fmt='W';
77
+ else fmt=substr(fmt,1,length(fmt)-1);
78
+ end;
79
+
80
+ /* apply lookups */
81
+ if cats(fmt) in ('DATETIME','B8601DN','B8601DN','B8601DT','B8601DT'
82
+ ,'B8601DZ','B8601DZ','DATEAMPM','DTDATE','DTMONYY','DTWKDATX','DTYEAR'
83
+ ,'DTYYQC','E8601DN','E8601DN','E8601DT','E8601DT','E8601DZ','E8601DZ')
84
+ then return('DATETIME');
85
+ else if fmt in ('DATE','YYMMDD','B8601DA','B8601DA','DAY','DDMMYY'
86
+ ,'DDMMYYB','DDMMYYC','DDMMYYD','DDMMYYN','DDMMYYP','DDMMYYS','DDMMYYx'
87
+ ,'DOWNAME','E8601DA','E8601DA','JULDAY','JULIAN','MMDDYY','MMDDYYB'
88
+ ,'MMDDYYC','MMDDYYD','MMDDYYN','MMDDYYP','MMDDYYS','MMDDYYx','MMYY'
89
+ ,'MMYYC','MMYYD','MMYYN','MMYYP','MMYYS','MMYYx','MONNAME','MONTH'
90
+ ,'MONYY','PDJULG','PDJULI','QTR','QTRR','WEEKDATE','WEEKDATX','WEEKDAY'
91
+ ,'WEEKU','WEEKV','WEEKW','WORDDATE','WORDDATX','YEAR','YYMM','YYMMC'
92
+ ,'YYMMD','YYMMDDB','YYMMDDC','YYMMDDD','YYMMDDN','YYMMDDP','YYMMDDS'
93
+ ,'YYMMDDx','YYMMN','YYMMP','YYMMS','YYMMx','YYMON','YYQ','YYQC','YYQD'
94
+ ,'YYQN','YYQP','YYQR','YYQRC','YYQRD','YYQRN','YYQRP','YYQRS','YYQRx'
95
+ ,'YYQS','YYQx','YYQZ') then return('DATE');
96
+ else if fmt in ('TIME','B8601LZ','B8601LZ','B8601TM','B8601TM','B8601TZ'
97
+ ,'B8601TZ','E8601LZ','E8601LZ','E8601TM','E8601TM','E8601TZ','E8601TZ'
98
+ ,'HHMM','HOUR','MMSS','TIMEAMPM','TOD') then return('TIME');
99
+ else return('NUM');
100
+ end;
101
+ endsub;
102
+
103
+ %if &wrap=YES %then %do;
104
+ quit;
105
+ %end;
106
+
107
+ /* insert the CMPLIB if not already there */
108
+ %let cmpval=%sysfunc(getoption(cmplib));
109
+ %let found=0;
110
+ %do i=1 %to %sysfunc(countw(&cmpval,%str( %(%))));
111
+ %let var=%scan(&cmpval,&i,%str( %(%)));
112
+ %if &var=&lib..&cat %then %let found=1;
113
+ %end;
114
+ %if &found=0 %then %do;
115
+ options insert=(CMPLIB=(&lib..&cat));
116
+ %end;
117
+
118
+ %mend mcf_getfmttype;
@@ -32,12 +32,12 @@
32
32
  > outa=3 outb=4 outc=5 outd=0
33
33
 
34
34
  @param [out] wrap= (NO) Choose YES to add the proc fcmp wrapper.
35
- @param [out] insert_cmplib= (NO) Choose YES to insert the package into the
36
- CMPLIB reference.
37
35
  @param [out] lib= (work) The output library in which to create the catalog.
38
36
  @param [out] cat= (sasjs) The output catalog in which to create the package.
39
37
  @param [out] pkg= (utils) The output package in which to create the function.
40
38
  Uses a 3 part format: libref.catalog.package
39
+ @param [out] insert_cmplib= DEPRECATED - The CMPLIB option is checked and
40
+ values inserted only if needed.
41
41
 
42
42
  <h4> SAS Macros </h4>
43
43
  @li mcf_init.sas
@@ -49,12 +49,12 @@
49
49
  **/
50
50
 
51
51
  %macro mcf_length(wrap=NO
52
- ,insert_cmplib=NO
52
+ ,insert_cmplib=DEPRECATED
53
53
  ,lib=WORK
54
54
  ,cat=SASJS
55
55
  ,pkg=UTILS
56
56
  )/*/STORE SOURCE*/;
57
-
57
+ %local i var cmpval found;
58
58
  %if %mcf_init(mcf_length)=1 %then %return;
59
59
 
60
60
  %if &wrap=YES %then %do;
@@ -76,7 +76,14 @@ endsub;
76
76
  quit;
77
77
  %end;
78
78
 
79
- %if &insert_cmplib=YES %then %do;
79
+ /* insert the CMPLIB if not already there */
80
+ %let cmpval=%sysfunc(getoption(cmplib));
81
+ %let found=0;
82
+ %do i=1 %to %sysfunc(countw(&cmpval,%str( %(%))));
83
+ %let var=%scan(&cmpval,&i,%str( %(%)));
84
+ %if &var=&lib..&cat %then %let found=1;
85
+ %end;
86
+ %if &found=0 %then %do;
80
87
  options insert=(CMPLIB=(&lib..&cat));
81
88
  %end;
82
89
 
@@ -47,12 +47,12 @@
47
47
 
48
48
 
49
49
  @param [out] wrap= (NO) Choose YES to add the proc fcmp wrapper.
50
- @param [out] insert_cmplib= (NO) Choose YES to insert the package into the
51
- CMPLIB reference.
52
50
  @param [out] lib= (work) The output library in which to create the catalog.
53
51
  @param [out] cat= (sasjs) The output catalog in which to create the package.
54
52
  @param [out] pkg= (utils) The output package in which to create the function.
55
53
  Uses a 3 part format: libref.catalog.package
54
+ @param [out] insert_cmplib= DEPRECATED - The CMPLIB option is checked and
55
+ values inserted only if needed.
56
56
 
57
57
  <h4> SAS Macros </h4>
58
58
  @li mcf_init.sas
@@ -64,12 +64,12 @@
64
64
  **/
65
65
 
66
66
  %macro mcf_stpsrv_header(wrap=NO
67
- ,insert_cmplib=NO
67
+ ,insert_cmplib=DEPRECATED
68
68
  ,lib=WORK
69
69
  ,cat=SASJS
70
70
  ,pkg=UTILS
71
71
  )/*/STORE SOURCE*/;
72
-
72
+ %local i var cmpval found;
73
73
  %if %mcf_init(stpsrv_header)=1 %then %return;
74
74
 
75
75
  %if &wrap=YES %then %do;
@@ -96,7 +96,14 @@ endsub;
96
96
  quit;
97
97
  %end;
98
98
 
99
- %if &insert_cmplib=YES %then %do;
99
+ /* insert the CMPLIB if not already there */
100
+ %let cmpval=%sysfunc(getoption(cmplib));
101
+ %let found=0;
102
+ %do i=1 %to %sysfunc(countw(&cmpval,%str( %(%))));
103
+ %let var=%scan(&cmpval,&i,%str( %(%)));
104
+ %if &var=&lib..&cat %then %let found=1;
105
+ %end;
106
+ %if &found=0 %then %do;
100
107
  options insert=(CMPLIB=(&lib..&cat));
101
108
  %end;
102
109
 
@@ -32,12 +32,12 @@
32
32
  run;
33
33
 
34
34
  @param [out] wrap= (NO) Choose YES to add the proc fcmp wrapper.
35
- @param [out] insert_cmplib= (NO) Choose YES to insert the package into the
36
- CMPLIB reference.
37
35
  @param [out] lib= (work) The output library in which to create the catalog.
38
36
  @param [out] cat= (sasjs) The output catalog in which to create the package.
39
37
  @param [out] pkg= (utils) The output package in which to create the function.
40
38
  Uses a 3 part format: libref.catalog.package
39
+ @param [out] insert_cmplib= DEPRECATED - The CMPLIB option is checked and
40
+ values inserted only if needed.
41
41
 
42
42
  <h4> SAS Macros </h4>
43
43
  @li mcf_init.sas
@@ -49,12 +49,12 @@
49
49
  **/
50
50
 
51
51
  %macro mcf_string2file(wrap=NO
52
- ,insert_cmplib=NO
52
+ ,insert_cmplib=DEPRECATED
53
53
  ,lib=WORK
54
54
  ,cat=SASJS
55
55
  ,pkg=UTILS
56
56
  )/*/STORE SOURCE*/;
57
-
57
+ %local i var cmpval found;
58
58
  %if %mcf_init(mcf_string2file)=1 %then %return;
59
59
 
60
60
  %if &wrap=YES %then %do;
@@ -81,7 +81,14 @@ endsub;
81
81
  quit;
82
82
  %end;
83
83
 
84
- %if &insert_cmplib=YES %then %do;
84
+ /* insert the CMPLIB if not already there */
85
+ %let cmpval=%sysfunc(getoption(cmplib));
86
+ %let found=0;
87
+ %do i=1 %to %sysfunc(countw(&cmpval,%str( %(%))));
88
+ %let var=%scan(&cmpval,&i,%str( %(%)));
89
+ %if &var=&lib..&cat %then %let found=1;
90
+ %end;
91
+ %if &found=0 %then %do;
85
92
  options insert=(CMPLIB=(&lib..&cat));
86
93
  %end;
87
94
 
@@ -164,7 +164,7 @@ data _null_;
164
164
  put ' %put &sysmacroname: Switching to DATASTEP engine; ';
165
165
  put ' %goto datastep; ';
166
166
  put ' %end; ';
167
- put ' data &tempds /view=&tempds;set &ds; ';
167
+ put ' data &tempds;set &ds; ';
168
168
  put ' %if &fmt=N %then format _numeric_ best32.;; ';
169
169
  put ' /* PRETTY is necessary to avoid line truncation in large files */ ';
170
170
  put ' proc json out=&jref pretty ';
@@ -215,7 +215,7 @@ data _null_;
215
215
  put ' %end; ';
216
216
  put ' other = [best.]; ';
217
217
  put ' ';
218
- put ' data &tempds/view=&tempds; ';
218
+ put ' data &tempds; ';
219
219
  put ' attrib _all_ label=''''; ';
220
220
  put ' %do i=1 %to &numcols; ';
221
221
  put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
@@ -277,8 +277,7 @@ data _null_;
277
277
  put ' %end; ';
278
278
  put ' ';
279
279
  put ' proc sql; ';
280
- put ' drop view &tempds; ';
281
- put ' drop table &colinfo; ';
280
+ put ' drop table &colinfo, &tempds; ';
282
281
  put ' ';
283
282
  put ' %if &showmeta=YES %then %do; ';
284
283
  put ' data _null_; file &jref encoding=''utf-8'' mod; ';
package/package.json CHANGED
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "@sasjs/cli": "3.6.0"
37
37
  },
38
- "version": "4.2.0"
38
+ "version": "4.4.0"
39
39
  }
@@ -308,7 +308,7 @@ data _null_;
308
308
  put ' %put &sysmacroname: Switching to DATASTEP engine; ';
309
309
  put ' %goto datastep; ';
310
310
  put ' %end; ';
311
- put ' data &tempds /view=&tempds;set &ds; ';
311
+ put ' data &tempds;set &ds; ';
312
312
  put ' %if &fmt=N %then format _numeric_ best32.;; ';
313
313
  put ' /* PRETTY is necessary to avoid line truncation in large files */ ';
314
314
  put ' proc json out=&jref pretty ';
@@ -359,7 +359,7 @@ data _null_;
359
359
  put ' %end; ';
360
360
  put ' other = [best.]; ';
361
361
  put ' ';
362
- put ' data &tempds/view=&tempds; ';
362
+ put ' data &tempds; ';
363
363
  put ' attrib _all_ label=''''; ';
364
364
  put ' %do i=1 %to &numcols; ';
365
365
  put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
@@ -421,8 +421,7 @@ data _null_;
421
421
  put ' %end; ';
422
422
  put ' ';
423
423
  put ' proc sql; ';
424
- put ' drop view &tempds; ';
425
- put ' drop table &colinfo; ';
424
+ put ' drop table &colinfo, &tempds; ';
426
425
  put ' ';
427
426
  put ' %if &showmeta=YES %then %do; ';
428
427
  put ' data _null_; file &jref encoding=''utf-8'' mod; ';