@sasjs/core 4.1.0 → 4.3.2

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
@@ -181,7 +181,7 @@ When contributing to this library, it is therefore important to ensure that all
181
181
  - The closing `%mend;` should **not** contain the macro name.
182
182
  - All macros should be defined with brackets, even if no variables are needed - ie `%macro x();` not `%macro x;`
183
183
  - Mandatory parameters should be positional, all optional parameters should be keyword (var=) style.
184
- - All dataset references must be 2 level (eg `work.blah`, not `blah`). This is to avoid contention when options [DATASTMTCHK](https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000279064.htm)=ALLKEYWORDS is in effect.
184
+ - All dataset references must be 2 level (eg `work.blah`, not `blah`). This is to avoid contention when options [DATASTMTCHK](https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000279064.htm)=ALLKEYWORDS is in effect, or the [USER](https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lrcon/n18m1vkqmeo4esn1moikt23zhp8s.htm) library is active.
185
185
  - Avoid naming collisions! All macro variables should be local scope. Use system generated work tables where possible - eg `data ; set sashelp.class; run; data &output; set &syslast; run;`
186
186
  - Where global macro variables are absolutely necessary, they should make use of `&sasjs_prefix` - see mp_init.sas
187
187
  - The use of `quit;` for `proc sql` is optional unless you are looking to benefit from the timing statistics.
@@ -195,7 +195,9 @@ When contributing to this library, it is therefore important to ensure that all
195
195
 
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
- * (None as yet)
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';
@@ -24,20 +24,22 @@ Usage:
24
24
  %webout(OBJ,example2) * Object format, easier to work with ;
25
25
  %webout(CLOSE)
26
26
  ;;;;
27
- %mp_createwebservice(path=/Public/app/common,name=appInit,code=ft15f001,replace=YES)
27
+ %mp_createwebservice(path=/Public/app/common,name=appInit,replace=YES)
28
28
 
29
29
  <h4> SAS Macros </h4>
30
30
  @li mf_getplatform.sas
31
31
  @li mm_createwebservice.sas
32
32
  @li mv_createwebservice.sas
33
33
 
34
- @param path= The full folder path where the service will be created
35
- @param name= Service name. Avoid spaces.
36
- @param desc= The description of the service (optional)
37
- @param precode= Space separated list of filerefs, pointing to the code that
38
- needs to be attached to the beginning of the service (optional)
39
- @param code= Space seperated fileref(s) of the actual code to be added
40
- @param replace= select YES to replace any existing service in that location
34
+ @param [in,out] path= The full folder path where the service will be created
35
+ @param [in,out] name= Service name. Avoid spaces.
36
+ @param [in] desc= The description of the service (optional)
37
+ @param [in] precode= Space separated list of filerefs, pointing to the code
38
+ that needs to be attached to the beginning of the service (optional)
39
+ @param [in] code= (ft15f001) Space seperated fileref(s) of the actual code to
40
+ be added
41
+ @param [in] replace= (YES) Select YES to replace any existing service in that
42
+ location
41
43
 
42
44
 
43
45
  @version 9.2
@@ -51,6 +51,7 @@
51
51
  data _null_;
52
52
  set work.&tempds end=last;
53
53
  length fref $8;
54
+ fref='';
54
55
  rc=filename(fref,filepath);
55
56
  rc=fdelete(fref);
56
57
  if rc then do;
@@ -82,7 +82,8 @@ data &out_ds(compress=no
82
82
  keep=file_or_folder filepath filename ext msg directory level
83
83
  );
84
84
  length directory filepath $500 fref fref2 $8 file_or_folder $6 filename $80
85
- ext $20 msg $200;
85
+ ext $20 msg $200 foption $16;
86
+ if _n_=1 then call missing(of _all_);
86
87
  retain level &level;
87
88
  %if &fref=0 %then %do;
88
89
  rc = filename(fref, "&path");
@@ -93,7 +94,13 @@ data &out_ds(compress=no
93
94
  %end;
94
95
  if rc = 0 then do;
95
96
  did = dopen(fref);
96
- directory=dinfo(did,'Directory');
97
+ /* attribute is OS-dependent - could be "Directory" or "Directory Name" */
98
+ numopts=doptnum(did);
99
+ do i=1 to numopts;
100
+ foption=doptname(did,i);
101
+ if foption=:'Directory' then i=numopts;
102
+ end;
103
+ directory=dinfo(did,foption);
97
104
  if did=0 then do;
98
105
  putlog "NOTE: This directory is empty - " directory;
99
106
  msg=sysmsg();
@@ -1,23 +1,82 @@
1
1
  /**
2
2
  @file
3
- @brief Export a dataset to a CSV file
4
- @details Export to a file or a fileref
3
+ @brief Export a dataset to a CSV file WITH leading blanks
4
+ @details Export a dataset to a file or fileref, retaining leading blanks.
5
+
6
+ When using SASJS headerformat, the input statement is provided in the first
7
+ row of the CSV.
8
+
5
9
  Usage:
6
10
 
7
11
  %mp_ds2csv(sashelp.class,outref="%sysfunc(pathname(work))/file.csv")
8
12
 
9
- @param ds The dataset to be exported
10
- @param outfile= The output filename - should be quoted.
11
- @param outref= The output fileref (takes precedence if provided)
12
- @param outencoding= The output encoding to use (unquoted)
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
+
28
+ Why use mp_ds2csv over, say, proc export?
29
+
30
+ 1. Ability to retain leading blanks (this is a major one)
31
+ 2. Control the header format
32
+ 3. Simple one-liner
33
+
34
+ @param [in] ds The dataset to be exported
35
+ @param [in] dlm= (COMMA) The delimeter to apply. For SASJS, will always be
36
+ COMMA. Supported values:
37
+ @li COMMA
38
+ @li SEMICOLON
39
+ @param [in] headerformat= (LABEL) The format to use for the header section.
40
+ Valid values:
41
+ @li LABEL - Use the variable label (or name, if blank)
42
+ @li NAME - Use the variable name
43
+ @li SASJS - Used to create sasjs-formatted input CSVs, eg for use in
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).
50
+ @param [out] outfile= The output filename - should be quoted.
51
+ @param [out] outref= (0) The output fileref (takes precedence if provided)
52
+ @param [in] outencoding= (0) The output encoding to use (unquoted)
53
+ @param [in] termstr= (CRLF) The line seperator to use. For SASJS, will
54
+ always be CRLF. Valid values:
55
+ @li CRLF
56
+ @li LF
57
+
58
+ <h4> SAS Macros </h4>
59
+ @li mcf_getfmttype.sas
60
+ @li mf_getuniquename.sas
61
+ @li mf_getvarformat.sas
62
+ @li mf_getvarlist.sas
63
+ @li mf_getvartype.sas
13
64
 
14
65
  @version 9.2
15
66
  @author Allan Bowe (credit mjsq)
16
67
  **/
17
68
 
18
- %macro mp_ds2csv(ds, outref=0, outfile=, outencoding=0
69
+ %macro mp_ds2csv(ds
70
+ ,dlm=COMMA
71
+ ,outref=0
72
+ ,outfile=
73
+ ,outencoding=0
74
+ ,headerformat=LABEL
75
+ ,termstr=CRLF
19
76
  )/*/STORE SOURCE*/;
20
77
 
78
+ %local outloc delim i varlist var vcnt vat dsv vcom vmiss fmttype vfmt;
79
+
21
80
  %if not %sysfunc(exist(&ds)) %then %do;
22
81
  %put %str(WARN)ING: &ds does not exist;
23
82
  %return;
@@ -28,31 +87,126 @@
28
87
  %if &outencoding=0 %then %let outencoding=;
29
88
  %else %let outencoding=encoding="&outencoding";
30
89
 
31
- %local outloc;
32
90
  %if &outref=0 %then %let outloc=&outfile;
33
91
  %else %let outloc=&outref;
34
92
 
93
+ %if &headerformat=SASJS %then %do;
94
+ %let delim=",";
95
+ %let termstr=CRLF;
96
+ %mcf_getfmttype(wrap=YES)
97
+ %end;
98
+ %else %if &dlm=COMMA %then %let delim=",";
99
+ %else %let delim=";";
100
+
35
101
  /* credit to mjsq - https://stackoverflow.com/a/55642267 */
36
102
 
37
103
  /* first get headers */
38
104
  data _null_;
39
- file &outloc dlm=',' dsd &outencoding lrecl=32767;
40
- length header $ 2000;
105
+ file &outloc &outencoding lrecl=32767 termstr=&termstr;
106
+ length header $ 2000 varnm vfmt $32 dlm $1 fmttype $8;
107
+ call missing(of _all_);
41
108
  dsid=open("&ds.","i");
42
109
  num=attrn(dsid,"nvars");
110
+ dlm=&delim;
43
111
  do i=1 to num;
44
- header = cats(coalescec(varlabel(dsid,i),varname(dsid,i)));
112
+ varnm=upcase(varname(dsid,i));
113
+ if i=num then dlm='';
114
+ %if &headerformat=NAME %then %do;
115
+ header=cats(varnm,dlm);
116
+ %end;
117
+ %else %if &headerformat=LABEL %then %do;
118
+ header = cats(coalescec(varlabel(dsid,i),varnm),dlm);
119
+ %end;
120
+ %else %if &headerformat=SASJS %then %do;
121
+ if vartype(dsid,i)='C' then header=cats(varnm,':$char',varlen(dsid,i),'.');
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;
130
+ %end;
131
+ %else %do;
132
+ %put &sysmacroname: Invalid headerformat value (&headerformat);
133
+ %return;
134
+ %end;
45
135
  put header @;
46
136
  end;
47
137
  rc=close(dsid);
48
138
  run;
49
139
 
140
+ %let varlist=%mf_getvarlist(&ds);
141
+ %let vcnt=%sysfunc(countw(&varlist));
142
+
143
+ /**
144
+ * The $quote modifier (without a width) will take the length from the variable
145
+ * and increase by two. However this will lead to truncation where the value
146
+ * contains double quotes (which are doubled up). To get around this, scan the
147
+ * data to see the max number of double quotes, so that the appropriate width
148
+ * can be applied in the subsequent step.
149
+ */
150
+ data _null_;
151
+ set &ds end=last;
152
+ %do i=1 %to &vcnt;
153
+ %let var=%scan(&varlist,&i);
154
+ %if %mf_getvartype(&ds,&var)=C %then %do;
155
+ %let dsv1=%mf_getuniquename(prefix=csvcol1_);
156
+ %let dsv2=%mf_getuniquename(prefix=csvcol2_);
157
+ retain &dsv1 0;
158
+ &dsv2=length(&var)+countc(&var,'"');
159
+ if &dsv2>&dsv1 then &dsv1=&dsv2;
160
+ if last then call symputx(
161
+ "vlen&i"
162
+ /* should be no shorter than varlen, and no longer than 32767 */
163
+ ,cats('$quote',min(&dsv1+2,32767),'.')
164
+ ,'l'
165
+ );
166
+ %end;
167
+ %end;
168
+
169
+ %let vat=@;
170
+ %let vcom=&delim;
171
+ %let vmiss=%mf_getuniquename(prefix=csvcol3_);
50
172
  /* next, export data */
51
173
  data _null_;
52
174
  set &ds.;
53
- file &outloc mod dlm=',' dsd &outencoding lrecl=32767;
54
- put (_all_) (+0);
55
- run;
175
+ file &outloc mod dlm=&delim dsd &outencoding lrecl=32767 termstr=&termstr;
176
+ if _n_=1 then &vmiss=' ';
177
+ %do i=1 %to &vcnt;
178
+ %let var=%scan(&varlist,&i);
179
+ %if &i=&vcnt %then %do;
180
+ %let vat=;
181
+ %let vcom=;
182
+ %end;
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=;
56
196
 
197
+ /* must use period - in order to work in both 9.4 and Viya 3.5 */
198
+ if missing(&var) and &var ne %sysfunc(getoption(MISSING)) then do;
199
+ &vmiss=cats('.',&var);
200
+ put &vmiss &vat;
201
+ end;
202
+ else put &var &vfmt &vcom &vat;
203
+
204
+ %end;
205
+ %else %do;
206
+ %if &i ne &vcnt %then %let vcom=&delim;
207
+ put &var &&vlen&i &vcom &vat;
208
+ %end;
209
+ %end;
210
+ run;
57
211
 
58
212
  %mend mp_ds2csv;
@@ -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
package/base/mp_init.sas CHANGED
@@ -53,11 +53,9 @@ data _null_;
53
53
  run;
54
54
 
55
55
  options
56
- noautocorrect /* disallow misspelled procedure names */
57
56
  compress=CHAR /* default is none so ensure we have something! */
58
57
  datastmtchk=ALLKEYWORDS /* protection from overwriting input datasets */
59
- dsoptions=note2err /* undocumented - convert bad NOTEs to ERRs */
60
- %str(err)orcheck=STRICT /* catch errs in libname/filename statements */
58
+ errorcheck=STRICT /* catch errs in libname/filename statements */
61
59
  fmterr /* ensure err when a format cannot be found */
62
60
  mergenoby=%str(ERR)OR /* throw err when a merge has no BY variables */
63
61
  missing=. /* changing this can cause hard to detect errs */
@@ -69,6 +67,10 @@ options
69
67
  validvarname=V7 /* avoid special characters etc in variable names */
70
68
  varinitchk=%str(ERR)OR /* avoid data mistakes from variable name typos */
71
69
  varlenchk=%str(ERR)OR /* fail hard if truncation (data loss) can result */
70
+ %if %substr(&sysver,1,1) ne 4 %then %do;
71
+ noautocorrect /* disallow misspelled procedure names */
72
+ dsoptions=note2err /* undocumented - convert bad NOTEs to ERRs */
73
+ %end;
72
74
  ;
73
75
 
74
76
  %mend mp_init;
@@ -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
@@ -157,7 +157,12 @@
157
157
  ));
158
158
  %do i=1 %to &numcols;
159
159
  length &&name&i $&&len&i;
160
- &&name&i=left(put(&&newname&i,&&fmt&i));
160
+ %if &&typelong&i=num %then %do;
161
+ &&name&i=left(put(&&newname&i,&&fmt&i));
162
+ %end;
163
+ %else %do;
164
+ &&name&i=put(&&newname&i,&&fmt&i);
165
+ %end;
161
166
  drop &&newname&i;
162
167
  %end;
163
168
  if _error_ then call symputx('syscc',1012);
@@ -177,7 +182,7 @@
177
182
  %end;
178
183
  other = [best.];
179
184
 
180
- data &tempds/view=&tempds;
185
+ data &tempds;
181
186
  attrib _all_ label='';
182
187
  %do i=1 %to &numcols;
183
188
  %if &&typelong&i=char or &fmt=Y %then %do;
@@ -239,8 +244,7 @@
239
244
  %end;
240
245
 
241
246
  proc sql;
242
- drop view &tempds;
243
- drop table &colinfo;
247
+ drop table &colinfo, &tempds;
244
248
 
245
249
  %if &showmeta=YES %then %do;
246
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;
@@ -1,10 +1,8 @@
1
1
  /**
2
2
  @file
3
3
  @brief Prepares an audit table for stacking (re-applying) the changes.
4
- @details WORK IN PROGRESS!!
5
-
6
- When the underlying data from a Base Table is refreshed, it can be helpful
7
- to have any previously-applied changes, re-applied.
4
+ @details When the underlying data from a Base Table is refreshed, it can be
5
+ helpful to have any previously-applied changes, re-applied.
8
6
 
9
7
  Such situation might arise if you are applying those changes using a tool
10
8
  like [Data Controller for SAS®](https://datacontroller.io) - which records
@@ -23,23 +21,23 @@
23
21
 
24
22
  Essentially then, what this macro does, is turn a table like this:
25
23
 
26
- |MOVE_TYPE:$1.|TGTVAR_NM:$32.|IS_PK:best.|IS_DIFF:best.|TGTVAR_TYPE:$1.|OLDVAL_NUM:best32.|NEWVAL_NUM:best32.|OLDVAL_CHAR:$32765.|NEWVAL_CHAR:$32765.|
27
- |---|---|---|---|---|---|---|---|---|
28
- |`A `|`NAME `|`1 `|`-1 `|`C `|`. `|`. `|` `|`Newbie `|
29
- |`A `|`AGE `|`0 `|`-1 `|`N `|`. `|`13 `|` `|` `|
30
- |`A `|`HEIGHT `|`0 `|`-1 `|`N `|`. `|`65.3 `|` `|` `|
31
- |`A `|`SEX `|`0 `|`-1 `|`C `|`. `|`. `|` `|`F `|
32
- |`A `|`WEIGHT `|`0 `|`-1 `|`N `|`. `|`98 `|` `|` `|
33
- |`D `|`NAME `|`1 `|`-1 `|`C `|`. `|`. `|`Alfred `|` `|
34
- |`D `|`AGE `|`0 `|`-1 `|`N `|`14 `|`. `|` `|` `|
35
- |`D `|`HEIGHT `|`0 `|`-1 `|`N `|`69 `|`. `|` `|` `|
36
- |`D `|`SEX `|`0 `|`-1 `|`C `|`. `|`. `|`M `|` `|
37
- |`D `|`WEIGHT `|`0 `|`-1 `|`N `|`112.5 `|`. `|` `|` `|
38
- |`M `|`NAME `|`1 `|`0 `|`C `|`. `|`. `|`Alice `|`Alice `|
39
- |`M `|`AGE `|`0 `|`1 `|`N `|`13 `|`99 `|` `|` `|
40
- |`M `|`HEIGHT `|`0 `|`0 `|`N `|`56.5 `|`56.5 `|` `|` `|
41
- |`M `|`SEX `|`0 `|`0 `|`C `|`. `|`. `|`F `|`F `|
42
- |`M `|`WEIGHT `|`0 `|`0 `|`N `|`84 `|`84 `|` `|` `|
24
+ |KEY_HASH:$32.|MOVE_TYPE:$1.|TGTVAR_NM:$32.|IS_PK:best.|IS_DIFF:best.|TGTVAR_TYPE:$1.|OLDVAL_NUM:best32.|NEWVAL_NUM:best32.|OLDVAL_CHAR:$32765.|NEWVAL_CHAR:$32765.|
25
+ |---|---|---|---|---|---|---|---|---|---|
26
+ |`27AA6F7581052E7FF48E1BCA901313FB `|`A `|`NAME `|`1 `|`-1 `|`C `|`. `|`. `|` `|`Newbie `|
27
+ |`27AA6F7581052E7FF48E1BCA901313FB `|`A `|`AGE `|`0 `|`-1 `|`N `|`. `|`13 `|` `|` `|
28
+ |`27AA6F7581052E7FF48E1BCA901313FB `|`A `|`HEIGHT `|`0 `|`-1 `|`N `|`. `|`65.3 `|` `|` `|
29
+ |`27AA6F7581052E7FF48E1BCA901313FB `|`A `|`SEX `|`0 `|`-1 `|`C `|`. `|`. `|` `|`F `|
30
+ |`27AA6F7581052E7FF48E1BCA901313FB `|`A `|`WEIGHT `|`0 `|`-1 `|`N `|`. `|`98 `|` `|` `|
31
+ |`86703FDE9E87DD5C0F8E1072545D0128 `|`D `|`NAME `|`1 `|`-1 `|`C `|`. `|`. `|`Alfred `|` `|
32
+ |`86703FDE9E87DD5C0F8E1072545D0128 `|`D `|`AGE `|`0 `|`-1 `|`N `|`14 `|`. `|` `|` `|
33
+ |`86703FDE9E87DD5C0F8E1072545D0128 `|`D `|`HEIGHT `|`0 `|`-1 `|`N `|`69 `|`. `|` `|` `|
34
+ |`86703FDE9E87DD5C0F8E1072545D0128 `|`D `|`SEX `|`0 `|`-1 `|`C `|`. `|`. `|`M `|` `|
35
+ |`86703FDE9E87DD5C0F8E1072545D0128 `|`D `|`WEIGHT `|`0 `|`-1 `|`N `|`112.5 `|`. `|` `|` `|
36
+ |`64489C85DC2FE0787B85CD87214B3810 `|`M `|`NAME `|`1 `|`0 `|`C `|`. `|`. `|`Alice `|`Alice `|
37
+ |`64489C85DC2FE0787B85CD87214B3810 `|`M `|`AGE `|`0 `|`1 `|`N `|`13 `|`99 `|` `|` `|
38
+ |`64489C85DC2FE0787B85CD87214B3810 `|`M `|`HEIGHT `|`0 `|`0 `|`N `|`56.5 `|`56.5 `|` `|` `|
39
+ |`64489C85DC2FE0787B85CD87214B3810 `|`M `|`SEX `|`0 `|`0 `|`C `|`. `|`. `|`F `|`F `|
40
+ |`64489C85DC2FE0787B85CD87214B3810 `|`M `|`WEIGHT `|`0 `|`0 `|`N `|`84 `|`84 `|` `|` `|
43
41
 
44
42
  Into three tables like this:
45
43
 
@@ -67,7 +65,7 @@
67
65
  The macro is also flexible where columns have been added or removed from
68
66
  the base table UNLESS there is a change to the primary key.
69
67
 
70
- Changes to the primary key are NOT supported, and are likely to cause
68
+ Changes to the primary key fields are NOT supported, and are likely to cause
71
69
  unexpected results.
72
70
 
73
71
  The following pre-flight checks are made:
@@ -184,7 +182,6 @@
184
182
  @param [out] outadd= (work.outadd) Output table containing additional records
185
183
  @param [out] outdel= (work.outdel) Output table containing deleted records
186
184
 
187
-
188
185
  <h4> SAS Macros </h4>
189
186
  @li mf_existvarlist.sas
190
187
  @li mf_getquotedstr.sas
@@ -196,7 +193,6 @@
196
193
  @li mp_abort.sas
197
194
  @li mp_ds2squeeze.sas
198
195
 
199
-
200
196
  <h4> Related Macros </h4>
201
197
  @li mp_coretable.sas
202
198
  @li mp_stackdiffs.test.sas
@@ -1,12 +1,10 @@
1
1
  /**
2
- @file mp_testservice.sas
3
- @brief Will execute a test against a SASjs web service on SAS 9 or Viya
2
+ @file
3
+ @brief Will execute a SASjs web service on SAS 9 or Viya
4
4
  @details Prepares the input files and retrieves the resulting datasets from
5
5
  the response JSON.
6
6
 
7
- %mp_testjob(
8
- duration=60*5
9
- )
7
+
10
8
 
11
9
  Note - the _webout fileref should NOT be assigned prior to running this macro.
12
10
 
@@ -14,6 +12,10 @@
14
12
  @param [in] inputfiles=(0) A list of space seperated fileref:filename pairs as
15
13
  follows:
16
14
  inputfiles=inref:filename inref2:filename2
15
+ @param [in] inputdatasets= (0) All datasets in this space seperated list are
16
+ converted into SASJS-formatted CSVs (see mp_ds2csv.sas) files and added to
17
+ the list of `inputfiles` for ingestion. The dataset will be sent with the
18
+ same name (no need for a colon modifier).
17
19
  @param [in] inputparams=(0) A dataset containing name/value pairs in the
18
20
  following format:
19
21
  |name:$32|value:$1000|
@@ -38,9 +40,13 @@
38
40
  @li mf_getuniquename.sas
39
41
  @li mp_abort.sas
40
42
  @li mp_binarycopy.sas
43
+ @li mp_ds2csv.sas
41
44
  @li mv_getjobresult.sas
42
45
  @li mv_jobflow.sas
43
46
 
47
+ <h4> Related Programs </h4>
48
+ @li mp_testservice.test.sas
49
+
44
50
  @version 9.4
45
51
  @author Allan Bowe
46
52
 
@@ -48,6 +54,7 @@
48
54
 
49
55
  %macro mp_testservice(program,
50
56
  inputfiles=0,
57
+ inputdatasets=0,
51
58
  inputparams=0,
52
59
  debug=log,
53
60
  mdebug=0,
@@ -56,7 +63,7 @@
56
63
  viyaresult=WEBOUT_JSON,
57
64
  viyacontext=SAS Job Execution compute context
58
65
  )/*/STORE SOURCE*/;
59
- %local dbg;
66
+ %local dbg pcnt fref1 webref i webcount var platform;
60
67
  %if &mdebug=1 %then %do;
61
68
  %put &sysmacroname entry vars:;
62
69
  %put _local_;
@@ -64,7 +71,6 @@
64
71
  %else %let dbg=*;
65
72
 
66
73
  /* sanitise inputparams */
67
- %local pcnt;
68
74
  %let pcnt=0;
69
75
  %if &inputparams ne 0 %then %do;
70
76
  data _null_;
@@ -86,17 +92,25 @@
86
92
  )
87
93
  %end;
88
94
 
95
+ /* convert inputdatasets to filerefs */
96
+ %if "&inputdatasets" ne "0" %then %do;
97
+ %if %quote(&inputfiles)=0 %then %let inputfiles=;
98
+ %do i=1 %to %sysfunc(countw(&inputdatasets,%str( )));
99
+ %let var=%scan(&inputdatasets,&i,%str( ));
100
+ %local dsref&i;
101
+ %let dsref&i=%mf_getuniquefileref();
102
+ %mp_ds2csv(&var,outref=&&dsref&i,headerformat=SASJS)
103
+ %let inputfiles=&inputfiles &&dsref&i:%scan(&var,-1,.);
104
+ %end;
105
+ %end;
106
+
89
107
 
90
- %local fref1 webref;
91
108
  %let fref1=%mf_getuniquefileref();
92
109
  %let webref=%mf_getuniquefileref();
93
-
94
- %local platform;
95
110
  %let platform=%mf_getplatform();
96
111
  %if &platform=SASMETA %then %do;
97
112
 
98
113
  /* parse the input files */
99
- %local webcount i var;
100
114
  %if %quote(&inputfiles) ne 0 %then %do;
101
115
  %let webcount=%sysfunc(countw(&inputfiles));
102
116
  %put &=webcount;
@@ -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
 
@@ -177,6 +177,7 @@ run;
177
177
 
178
178
  data &outds (keep=stpuri prompturi fileuri texturi);
179
179
  length stpuri prompturi fileuri texturi serveruri $256 ;
180
+ if _n_=1 then call missing (of _all_);
180
181
  set &outds;
181
182
 
182
183
  /* final checks on uris */
@@ -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 ';
@@ -190,7 +190,12 @@ data _null_;
190
190
  put ' )); ';
191
191
  put ' %do i=1 %to &numcols; ';
192
192
  put ' length &&name&i $&&len&i; ';
193
- put ' &&name&i=left(put(&&newname&i,&&fmt&i)); ';
193
+ put ' %if &&typelong&i=num %then %do; ';
194
+ put ' &&name&i=left(put(&&newname&i,&&fmt&i)); ';
195
+ put ' %end; ';
196
+ put ' %else %do; ';
197
+ put ' &&name&i=put(&&newname&i,&&fmt&i); ';
198
+ put ' %end; ';
194
199
  put ' drop &&newname&i; ';
195
200
  put ' %end; ';
196
201
  put ' if _error_ then call symputx(''syscc'',1012); ';
@@ -210,7 +215,7 @@ data _null_;
210
215
  put ' %end; ';
211
216
  put ' other = [best.]; ';
212
217
  put ' ';
213
- put ' data &tempds/view=&tempds; ';
218
+ put ' data &tempds; ';
214
219
  put ' attrib _all_ label=''''; ';
215
220
  put ' %do i=1 %to &numcols; ';
216
221
  put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
@@ -272,8 +277,7 @@ data _null_;
272
277
  put ' %end; ';
273
278
  put ' ';
274
279
  put ' proc sql; ';
275
- put ' drop view &tempds; ';
276
- put ' drop table &colinfo; ';
280
+ put ' drop table &colinfo, &tempds; ';
277
281
  put ' ';
278
282
  put ' %if &showmeta=YES %then %do; ';
279
283
  put ' data _null_; file &jref encoding=''utf-8'' mod; ';
@@ -41,7 +41,11 @@ run;
41
41
 
42
42
  filename __mc1 temp;
43
43
  filename __mc2 temp;
44
- data &outds; length serveruri servername $200; stop;run;
44
+ data &outds;
45
+ length serveruri servername $200;
46
+ call missing (of _all_);
47
+ stop;
48
+ run;
45
49
  %do x=1 %to &repocnt;
46
50
  options metarepository=&&repo&x;
47
51
  proc metadata in=
@@ -60,13 +64,16 @@ data &outds; length serveruri servername $200; stop;run;
60
64
  data _null_;
61
65
  file __mc2;
62
66
  put '<SXLEMAP version="1.2" name="SASContexts"><TABLE name="SASContexts">';
63
- put "<TABLE-PATH syntax='XPath'>/GetMetadataObjects/Objects/ServerContext</TABLE-PATH>";
67
+ put "<TABLE-PATH syntax='XPath'>/GetMetadataObjects/Objects/ServerContext";
68
+ put "</TABLE-PATH>";
64
69
  put '<COLUMN name="serveruri">';
65
- put "<PATH syntax='XPath'>/GetMetadataObjects/Objects/ServerContext/@Id</PATH>";
70
+ put "<PATH syntax='XPath'>/GetMetadataObjects/Objects/ServerContext/@Id";
71
+ put "</PATH>";
66
72
  put "<TYPE>character</TYPE><DATATYPE>string</DATATYPE><LENGTH>200</LENGTH>";
67
73
  put '</COLUMN>';
68
74
  put '<COLUMN name="servername">';
69
- put "<PATH syntax='XPath'>/GetMetadataObjects/Objects/ServerContext/@Name</PATH>";
75
+ put "<PATH syntax='XPath'>/GetMetadataObjects/Objects/ServerContext/@Name";
76
+ put "</PATH>";
70
77
  put "<TYPE>character</TYPE><DATATYPE>string</DATATYPE><LENGTH>200</LENGTH>";
71
78
  put '</COLUMN>';
72
79
  put '</TABLE></SXLEMAP>';
package/package.json CHANGED
@@ -35,5 +35,5 @@
35
35
  "devDependencies": {
36
36
  "@sasjs/cli": "3.6.0"
37
37
  },
38
- "version": "4.1.0"
38
+ "version": "4.3.2"
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 ';
@@ -334,7 +334,12 @@ data _null_;
334
334
  put ' )); ';
335
335
  put ' %do i=1 %to &numcols; ';
336
336
  put ' length &&name&i $&&len&i; ';
337
- put ' &&name&i=left(put(&&newname&i,&&fmt&i)); ';
337
+ put ' %if &&typelong&i=num %then %do; ';
338
+ put ' &&name&i=left(put(&&newname&i,&&fmt&i)); ';
339
+ put ' %end; ';
340
+ put ' %else %do; ';
341
+ put ' &&name&i=put(&&newname&i,&&fmt&i); ';
342
+ put ' %end; ';
338
343
  put ' drop &&newname&i; ';
339
344
  put ' %end; ';
340
345
  put ' if _error_ then call symputx(''syscc'',1012); ';
@@ -354,7 +359,7 @@ data _null_;
354
359
  put ' %end; ';
355
360
  put ' other = [best.]; ';
356
361
  put ' ';
357
- put ' data &tempds/view=&tempds; ';
362
+ put ' data &tempds; ';
358
363
  put ' attrib _all_ label=''''; ';
359
364
  put ' %do i=1 %to &numcols; ';
360
365
  put ' %if &&typelong&i=char or &fmt=Y %then %do; ';
@@ -416,8 +421,7 @@ data _null_;
416
421
  put ' %end; ';
417
422
  put ' ';
418
423
  put ' proc sql; ';
419
- put ' drop view &tempds; ';
420
- put ' drop table &colinfo; ';
424
+ put ' drop table &colinfo, &tempds; ';
421
425
  put ' ';
422
426
  put ' %if &showmeta=YES %then %do; ';
423
427
  put ' data _null_; file &jref encoding=''utf-8'' mod; ';