@sasjs/core 2.54.1 → 2.55.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.
@@ -12,6 +12,10 @@
12
12
 
13
13
  @param libds library.dataset
14
14
  @return output returns 1 or 0
15
+
16
+ <h4> Related Macros </h4>
17
+ @li mf_existds.test.sas
18
+
15
19
  @warning Untested on tables registered in metadata but not physically present
16
20
  @version 9.2
17
21
  @author Allan Bowe
@@ -10,6 +10,9 @@
10
10
  <h4> SAS Macros </h4>
11
11
  @li mf_getattrn.sas
12
12
 
13
+ <h4> Related Macros </h4>
14
+ @li mp_setkeyvalue.sas
15
+
13
16
  @param libds dataset to query
14
17
  @param variable the variable which contains the value to return.
15
18
  @param filter contents of where clause
@@ -8,6 +8,10 @@
8
8
 
9
9
  %mp_assertdsobs(sashelp.class) %* tests if any observations are present;
10
10
 
11
+ %mp_assertdsobs(sashelp.class,test=ATLEAST 10) %* pass if >9 obs present;
12
+
13
+ %mp_assertdsobs(sashelp.class,test=ATMOST 20) %* pass if <21 obs present;
14
+
11
15
  <h4> SAS Macros </h4>
12
16
  @li mf_nobs.sas
13
17
  @li mp_abort.sas
@@ -19,9 +23,9 @@
19
23
  @li HASOBS - Test is a PASS if the input dataset has any observations
20
24
  @li EMPTY - Test is a PASS if input dataset is empty
21
25
  @li EQUALS [integer] - Test passes if row count matches the provided integer
22
- @LI ATLEAST [integer] - Test passes if row count is more than or equal to
26
+ @li ATLEAST [integer] - Test passes if row count is more than or equal to
23
27
  the provided integer
24
- @LI ATMOST [integer] - Test passes if row count is less than or equal to
28
+ @li ATMOST [integer] - Test passes if row count is less than or equal to
25
29
  the provided integer
26
30
  @param [out] outds= (work.test_results) The output dataset to contain the
27
31
  results. If it does not exist, it will be created, with the following format:
@@ -17,8 +17,9 @@
17
17
  @li mf_isblank.sas
18
18
 
19
19
 
20
- @param list space separated list of datasets / views, WITHOUT libref
21
- @param libref= (WORK) Note - you can only drop from a single library at a time
20
+ @param [in] list space separated list of datasets / views, WITHOUT libref
21
+ @param [in] libref= (WORK) Note - you can only drop from one library at a time
22
+ @param [in] iftrue= (1=1) Conditionally drop tables, eg if &debug=N
22
23
 
23
24
  @version 9.2
24
25
  @author Allan Bowe
@@ -28,8 +29,11 @@
28
29
  %macro mp_dropmembers(
29
30
  list /* space separated list of datasets / views */
30
31
  ,libref=WORK /* can only drop from a single library at a time */
32
+ ,iftrue=%str(1=1)
31
33
  )/*/STORE SOURCE*/;
32
34
 
35
+ %if not(%eval(%unquote(&iftrue))) %then %return;
36
+
33
37
  %if %mf_isblank(&list) %then %do;
34
38
  %put NOTE: nothing to drop!;
35
39
  %return;
@@ -4,24 +4,27 @@
4
4
  @details Useful for capturing constraints before they are dropped / reapplied
5
5
  during an update.
6
6
 
7
- proc sql;
8
- create table work.example(
9
- TX_FROM float format=datetime19.,
10
- DD_TYPE char(16),
11
- DD_SOURCE char(2048),
12
- DD_SHORTDESC char(256),
13
- constraint pk primary key(tx_from, dd_type,dd_source),
14
- constraint unq unique(tx_from, dd_type),
15
- constraint nnn not null(DD_SHORTDESC)
16
- );
7
+ proc sql;
8
+ create table work.example(
9
+ TX_FROM float format=datetime19.,
10
+ DD_TYPE char(16),
11
+ DD_SOURCE char(2048),
12
+ DD_SHORTDESC char(256),
13
+ constraint pk primary key(tx_from, dd_type,dd_source),
14
+ constraint unq unique(tx_from, dd_type),
15
+ constraint nnn not null(DD_SHORTDESC)
16
+ );
17
17
 
18
18
  %mp_getconstraints(lib=work,ds=example,outds=work.constraints)
19
19
 
20
- @param lib= The target library (default=WORK)
21
- @param ds= The target dataset. Leave blank (default) for all datasets.
22
- @param outds the output dataset
20
+ @param [in] lib= (WORK) The target library
21
+ @param [in] ds= The target dataset. Leave blank (default) for all datasets.
22
+ @param [in] mdebug= (0) Set to 1 to preserve temp tables, print var values etc
23
+ @param [out] outds= (mp_getconstraints) the output dataset
23
24
 
24
25
  <h4> SAS Macros </h4>
26
+ @li mf_getuniquename.sas
27
+ @li mp_dropmembers.sas
25
28
 
26
29
  @version 9.2
27
30
  @author Allan Bowe
@@ -31,11 +34,33 @@
31
34
  %macro mp_getconstraints(lib=WORK
32
35
  ,ds=
33
36
  ,outds=mp_getconstraints
37
+ ,mdebug=0
34
38
  )/*/STORE SOURCE*/;
35
39
 
36
40
  %let lib=%upcase(&lib);
37
41
  %let ds=%upcase(&ds);
38
42
 
43
+ /**
44
+ * Neither dictionary tables nor sashelp provides a constraint order column,
45
+ * however they DO arrive in the correct order. So, create the col.
46
+ **/
47
+ %local vw;
48
+ %let vw=%mf_getuniquename(prefix=mp_getconstraints_vw_);
49
+ data &vw /view=&vw;
50
+ set sashelp.vcncolu;
51
+ where TABLE_CATALOG="&lib";
52
+
53
+ /* use retain approach to reset the constraint order with each constraint */
54
+ length tmp $1000;
55
+ retain tmp;
56
+ drop tmp;
57
+ if tmp ne catx('|',libref,table_name,constraint_type,constraint_name) then do;
58
+ constraint_order=1;
59
+ end;
60
+ else constraint_order+1;
61
+ tmp=catx('|',libref, table_name, constraint_type,constraint_name);
62
+ run;
63
+
39
64
  /* must use SQL as proc datasets does not support length changes */
40
65
  proc sql noprint;
41
66
  create table &outds as
@@ -44,8 +69,9 @@ create table &outds as
44
69
  ,a.constraint_type
45
70
  ,a.constraint_name
46
71
  ,b.column_name
72
+ ,b.constraint_order
47
73
  from dictionary.TABLE_CONSTRAINTS a
48
- left join dictionary.constraint_column_usage b
74
+ left join &vw b
49
75
  on upcase(a.TABLE_CATALOG)=upcase(b.TABLE_CATALOG)
50
76
  and upcase(a.TABLE_NAME)=upcase(b.TABLE_NAME)
51
77
  and a.constraint_name=b.constraint_name
@@ -58,6 +84,13 @@ create table &outds as
58
84
  and upcase(a.TABLE_NAME)="&ds"
59
85
  and upcase(b.TABLE_NAME)="&ds"
60
86
  %end;
87
+ order by libref, table_name, constraint_name, constraint_order
61
88
  ;
62
89
 
90
+ /* tidy up */
91
+ %mp_dropmembers(
92
+ &vw,
93
+ iftrue=(&mdebug=0)
94
+ )
95
+
63
96
  %mend mp_getconstraints;
@@ -0,0 +1,254 @@
1
+ /**
2
+ @file
3
+ @brief Extract the primary key fields from a table or library
4
+ @details Examines the constraints to identify primary key fields - indicated
5
+ by an explicit PK constraint, or a unique index that is also NOT NULL.
6
+
7
+ Can be executed at both table and library level. Supports both BASE engine
8
+ libraries and SQL Server.
9
+
10
+ Usage:
11
+
12
+ proc sql;
13
+ create table work.example(
14
+ TX_FROM float format=datetime19.,
15
+ DD_TYPE char(16),
16
+ DD_SOURCE char(2048),
17
+ DD_SHORTDESC char(256),
18
+ constraint pk primary key(tx_from, dd_type,dd_source),
19
+ constraint unq unique(tx_from, dd_type),
20
+ constraint nnn not null(DD_SHORTDESC)
21
+ );
22
+ %mp_getpk(work,ds=example)
23
+
24
+ Returns:
25
+
26
+
27
+ @param [in] lib The libref to examine
28
+ @param [in] ds= (0) Select the dataset to examine, else use 0 for all tables
29
+ @param [in] mdebug= (0) Set to 1 to preserve temp tables, print var values etc
30
+ @param [out] outds= (work.mp_getpk) The name of the output table to create.
31
+
32
+ <h4> SAS Macros </h4>
33
+ @li mf_getengine.sas
34
+ @li mf_getschema.sas
35
+ @li mp_dropmembers.sas
36
+ @li mp_getconstraints.sas
37
+
38
+ <h4> Related Macros </h4>
39
+ @li mp_getpk.test.sas
40
+
41
+ @version 9.3
42
+ @author Macro People Ltd
43
+ **/
44
+
45
+ %macro mp_getpk(
46
+ lib,
47
+ ds=0,
48
+ outds=work.mp_getpk,
49
+ mdebug=0
50
+ )/*/STORE SOURCE*/;
51
+
52
+
53
+ %local engine schema ds1 ds2 ds3 dsn tabs1 tabs2 sum pk4sure pkdefault finalpks;
54
+
55
+ %let lib=%upcase(&lib);
56
+ %let ds=%upcase(&ds);
57
+ %let engine=%mf_getengine(&lib);
58
+ %let schema=%mf_getschema(&lib);
59
+
60
+ %let ds1=%mf_getuniquename(prefix=getpk_ds1);
61
+ %let ds2=%mf_getuniquename(prefix=getpk_ds2);
62
+ %let ds3=%mf_getuniquename(prefix=getpk_ds3);
63
+ %let tabs1=%mf_getuniquename(prefix=getpk_tabs1);
64
+ %let tabs2=%mf_getuniquename(prefix=getpk_tabs2);
65
+ %let sum=%mf_getuniquename(prefix=getpk_sum);
66
+ %let pk4sure=%mf_getuniquename(prefix=getpk_pk4sure);
67
+ %let pkdefault=%mf_getuniquename(prefix=getpk_pkdefault);
68
+ %let finalpks=%mf_getuniquename(prefix=getpk_finalpks);
69
+
70
+ %local dbg;
71
+ %if &mdebug=1 %then %do;
72
+ %put &sysmacroname entry vars:;
73
+ %put _local_;
74
+ %end;
75
+ %else %let dbg=*;
76
+
77
+ proc sql;
78
+ create table &ds1 as
79
+ select libname as libref
80
+ ,upcase(memname) as dsn
81
+ ,memtype
82
+ ,upcase(name) as name
83
+ ,type
84
+ ,length
85
+ ,varnum
86
+ ,label
87
+ ,format
88
+ ,idxusage
89
+ ,notnull
90
+ from dictionary.columns
91
+ where upcase(libname)="&lib"
92
+ %if &ds ne 0 %then %do;
93
+ and upcase(memname)="&ds"
94
+ %end;
95
+ ;
96
+
97
+
98
+ %if &engine=SQLSVR %then %do;
99
+ proc sql;
100
+ connect using &lib;
101
+ create table work.&ds2 as
102
+ select * from connection to &lib(
103
+ select
104
+ s.name as SchemaName,
105
+ t.name as memname,
106
+ tc.name as name,
107
+ ic.key_ordinal as KeyOrderNr
108
+ from
109
+ sys.schemas s
110
+ inner join sys.tables t on s.schema_id=t.schema_id
111
+ inner join sys.indexes i on t.object_id=i.object_id
112
+ inner join sys.index_columns ic on i.object_id=ic.object_id
113
+ and i.index_id=ic.index_id
114
+ inner join sys.columns tc on ic.object_id=tc.object_id
115
+ and ic.column_id=tc.column_id
116
+ where i.is_primary_key=1
117
+ and s.name=%str(%')&schema%str(%')
118
+ order by t.name, ic.key_ordinal ;
119
+ );disconnect from &lib;
120
+ create table &ds3 as
121
+ select a.*
122
+ ,case when b.name is not null then 1 else 0 end as pk_ind
123
+ from work.&ds1 a
124
+ left join work.&ds2 b
125
+ on a.dsn=b.memname
126
+ and upcase(a.name)=upcase(b.name)
127
+ order by libref,dsn;
128
+ %end;
129
+ %else %do;
130
+
131
+ %if &ds = 0 %then %let dsn=;
132
+
133
+ /* get all constraints, in constraint order*/
134
+ %mp_getconstraints(lib=&lib,ds=&dsn,outds=work.&ds2)
135
+
136
+ /* extract cols that are clearly primary keys */
137
+ proc sql;
138
+ create table &pk4sure as
139
+ select libref
140
+ ,table_name
141
+ ,constraint_name
142
+ ,constraint_order
143
+ ,column_name as name
144
+ from work.&ds2
145
+ where constraint_type='PRIMARY'
146
+ order by 1,2,3,4;
147
+
148
+ /* extract unique constraints where every col is also NOT NULL */
149
+ proc sql;
150
+ create table &sum as
151
+ select a.libref
152
+ ,a.table_name
153
+ ,a.constraint_name
154
+ ,count(a.column_name) as unq_cnt
155
+ ,count(b.column_name) as nul_cnt
156
+ from work.&ds2(where=(constraint_type ='UNIQUE')) a
157
+ left join work.&ds2(where=(constraint_type ='NOT NULL')) b
158
+ on a.libref=b.libref
159
+ and a.table_name=b.table_name
160
+ and a.column_name=b.column_name
161
+ group by 1,2,3
162
+ having unq_cnt=nul_cnt;
163
+
164
+ /* extract cols from the relevant unique constraints */
165
+ create table &pkdefault as
166
+ select a.libref
167
+ ,a.table_name
168
+ ,a.constraint_name
169
+ ,b.constraint_order
170
+ ,b.column_name as name
171
+ from &sum a
172
+ left join &ds2(where=(constraint_type ='UNIQUE')) b
173
+ on a.libref=b.libref
174
+ and a.table_name=b.table_name
175
+ and a.constraint_name=b.constraint_name
176
+ order by 1,2,3,4;
177
+
178
+ /* create one table */
179
+ data &finalpks;
180
+ set &pkdefault &pk4sure ;
181
+ pk_ind=1;
182
+ /* if there are multiple unique constraints, take the first */
183
+ by libref table_name constraint_name;
184
+ retain keepme;
185
+ if first.table_name then keepme=1;
186
+ if first.constraint_name and not first.table_name then keepme=0;
187
+ if keepme=1;
188
+ run;
189
+
190
+ /* join back to starting table */
191
+ proc sql;
192
+ create table &ds3 as
193
+ select a.*
194
+ ,b.constraint_order
195
+ ,case when b.pk_ind=1 then 1 else 0 end as pk_ind
196
+ from work.&ds1 a
197
+ left join work.&finalpks b
198
+ on a.libref=b.libref
199
+ and a.dsn=b.table_name
200
+ and upcase(a.name)=upcase(b.name)
201
+ order by libref,dsn,constraint_order;
202
+ %end;
203
+
204
+
205
+ /* prepare tables */
206
+ proc sql;
207
+ create table work.&tabs1 as select
208
+ libname as libref
209
+ ,upcase(memname) as dsn
210
+ ,memtype
211
+ ,dbms_memtype
212
+ ,typemem
213
+ ,memlabel
214
+ ,nvar
215
+ ,compress
216
+ from dictionary.tables
217
+ where upcase(libname)="&lib"
218
+ %if &ds ne 0 %then %do;
219
+ and upcase(memname)="&ds"
220
+ %end;
221
+ ;
222
+ data &tabs2;
223
+ set &ds3;
224
+ length pk_fields $512;
225
+ retain pk_fields;
226
+ by libref dsn constraint_order;
227
+ if first.dsn then pk_fields='';
228
+ if pk_ind=1 then pk_fields=catx(' ',pk_fields,name);
229
+ if last.dsn then output;
230
+ run;
231
+
232
+ proc sql;
233
+ create table &outds as
234
+ select a.libref
235
+ ,a.dsn
236
+ ,a.memtype
237
+ ,a.dbms_memtype
238
+ ,a.typemem
239
+ ,a.memlabel
240
+ ,a.nvar
241
+ ,a.compress
242
+ ,b.pk_fields
243
+ from work.&tabs1 a
244
+ left join work.&tabs2 b
245
+ on a.libref=b.libref
246
+ and a.dsn=b.dsn;
247
+
248
+ /* tidy up */
249
+ %mp_dropmembers(
250
+ &ds1 &ds2 &ds3 &dsn &tabs1 &tabs2 &sum &pk4sure &pkdefault &finalpks,
251
+ iftrue=(&mdebug=0)
252
+ )
253
+
254
+ %mend mp_getpk;
@@ -9,11 +9,14 @@
9
9
  <h4> SAS Macros </h4>
10
10
  @li mf_existds.sas
11
11
 
12
- @param key Provide a key on which to perform the lookup
13
- @param value Provide a value
14
- @param type= either C or N will populate valc and valn respectively. C is
15
- default.
16
- @param libds= define the target table to hold the parameters
12
+ <h4> Related Macros </h4>
13
+ @li mf_getvalue.sas
14
+
15
+ @param [in] key Provide a key on which to perform the lookup
16
+ @param [in] value Provide a value
17
+ @param [in] type= either C or N will populate valc and valn respectively.
18
+ C is default.
19
+ @param [out] libds= define the target table to hold the parameters
17
20
 
18
21
  @version 9.2
19
22
  @author Allan Bowe
@@ -0,0 +1,118 @@
1
+ /**
2
+ @file
3
+ @brief Sorts a SAS dataset in place, preserving constraints
4
+ @details Generally if a dataset contains indexes, then it is not necessary to
5
+ sort it before performing operations such as merges / joins etc.
6
+ That said, there are a few edge cases where it can be desirable:
7
+
8
+ @li To improve performance for particular scenarios
9
+ @li To allow adjacent records to be viewed directly in the dataset
10
+ @li To reduce dataset size (eg when there are deleted records)
11
+
12
+ This macro will only work for BASE (V9) engine libraries. It works by
13
+ creating a copy of the dataset (without data, WITH constraints) in the same
14
+ library, appending a sorted view into it, and finally - renaming it.
15
+
16
+ Example usage:
17
+
18
+ proc sql;
19
+ create table work.example as
20
+ select * from sashelp.class;
21
+ alter table work.example
22
+ add constraint pk primary key(name);
23
+ %mp_sortinplace(work.example)
24
+
25
+ @param [in] libds The libref.datasetname that needs to be sorted
26
+
27
+ <h4> SAS Macros </h4>
28
+ @li mf_existds.sas
29
+ @li mf_getengine.sas
30
+ @li mf_getquotedstr.sas
31
+ @li mf_getuniquename.sas
32
+ @li mf_nobs.sas
33
+ @li mp_abort.sas
34
+ @li mp_getpk.sas
35
+
36
+ <h4> Related Macros </h4>
37
+ @li mp_sortinplace.test.sas
38
+
39
+ @version 9.2
40
+ @author Allan Bowe
41
+ @source https://github.com/sasjs/core
42
+
43
+ **/
44
+
45
+ %macro mp_sortinplace(libds
46
+ )/*/STORE SOURCE*/;
47
+
48
+ %local lib ds tempds1 tempds2 tempvw sortkey;
49
+
50
+ /* perform validations */
51
+ %mp_abort(iftrue=(%sysfunc(countc(&libds,.)) ne 1)
52
+ ,mac=mp_sortinplace
53
+ ,msg=%str(LIBDS (&libds) should have LIBREF.DATASET format)
54
+ )
55
+ %mp_abort(iftrue=(%mf_existds(&libds)=0)
56
+ ,mac=mp_sortinplace
57
+ ,msg=%str(&libds does not exist)
58
+ )
59
+
60
+ %let lib=%scan(&libds,1,.);
61
+ %let ds=%scan(&libds,2,.);
62
+ %mp_abort(iftrue=(%mf_getengine(&lib) ne V9)
63
+ ,mac=mp_sortinplace
64
+ ,msg=%str(&lib is not a BASE engine library)
65
+ )
66
+
67
+ /* grab a copy of the constraints so we know what to sort by */
68
+ %let tempds1=%mf_getuniquename(prefix=&sysmacroname);
69
+ %mp_getpk(lib=&lib,ds=&ds,outds=work.&tempds1)
70
+
71
+ %if %mf_nobs(work.&tempds1)=0 %then %do;
72
+ %put &sysmacroname: No PK found in &lib..&ds;
73
+ %put Sorting will not take place;
74
+ %return;
75
+ %end;
76
+
77
+ data _null_;
78
+ set work.&tempds1;
79
+ call symputx('sortkey',pk_fields);
80
+ run;
81
+
82
+
83
+ /* create empty copy, with ALL constraints, in the same library */
84
+ %let tempds2=%mf_getuniquename(prefix=&sysmacroname);
85
+ proc append base=&lib..&tempds2 data=&libds(obs=0);
86
+ run;
87
+
88
+ /* create sorted view */
89
+ %let tempvw=%mf_getuniquename(prefix=&sysmacroname);
90
+ proc sql;
91
+ create view work.&tempvw as select * from &lib..&ds
92
+ order by %mf_getquotedstr(&sortkey,quote=%str());
93
+
94
+ /* append sorted data */
95
+ proc append base=&lib..&tempds2 data=work.&tempvw;
96
+ run;
97
+
98
+ /* do validations */
99
+ %mp_abort(iftrue=(&syscc ne 0)
100
+ ,mac=mp_sortinplace
101
+ ,msg=%str(syscc=&syscc prior to replace operation)
102
+ )
103
+ %mp_abort(iftrue=(%mf_nobs(&lib..&tempds2) ne %mf_nobs(&lib..&ds))
104
+ ,mac=mp_sortinplace
105
+ ,msg=%str(new dataset has a different number of logical obs to the old)
106
+ )
107
+
108
+ /* drop old dataset */
109
+ proc sql;
110
+ drop table &lib..&ds;
111
+
112
+ /* rename the new dataset */
113
+ proc datasets library=&lib;
114
+ change &tempds2=&ds;
115
+ run;
116
+
117
+
118
+ %mend mp_sortinplace;
package/base/mp_unzip.sas CHANGED
@@ -7,19 +7,23 @@
7
7
 
8
8
  Usage:
9
9
 
10
- filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
10
+ filename mc url
11
+ "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
11
12
  %inc mc;
12
13
 
13
14
  %mp_unzip(ziploc="/some/file.zip",outdir=/some/folder)
14
15
 
15
- <h4> SAS Macros </h4>
16
- @li mf_mkdir.sas
17
- @li mf_getuniquefileref.sas
16
+ More info: https://blogs.sas.com/content/sasdummy/2015/05/11/using-filename-zip-to-unzip-and-read-data-files-in-sas/
18
17
 
19
18
  @param ziploc= Fileref or quoted full path to zip file ("/path/to/file.zip")
20
19
  @param outdir= (%sysfunc(pathname(work))) Directory in which to write the
21
20
  outputs (created if non existant)
22
21
 
22
+ <h4> SAS Macros </h4>
23
+ @li mf_mkdir.sas
24
+ @li mf_getuniquefileref.sas
25
+ @li mp_binarycopy.sas
26
+
23
27
  @version 9.4
24
28
  @author Allan Bowe
25
29
  @source https://github.com/sasjs/core
@@ -31,18 +35,20 @@
31
35
  ,outdir=%sysfunc(pathname(work))
32
36
  )/*/STORE SOURCE*/;
33
37
 
34
- %local fname1 fname2 fname3;
35
- %let fname1=%mf_getuniquefileref();
36
- %let fname2=%mf_getuniquefileref();
37
- %let fname3=%mf_getuniquefileref();
38
+ %local f1 f2 ;
39
+ %let f1=%mf_getuniquefileref();
40
+ %let f2=%mf_getuniquefileref();
38
41
 
39
42
  /* Macro variable &datazip would be read from the file */
40
- filename &fname1 ZIP &ziploc;
43
+ filename &f1 ZIP &ziploc;
44
+
45
+ /* create target folder */
46
+ %mf_mkdir(&outdir)
41
47
 
42
48
  /* Read the "members" (files) from the ZIP file */
43
49
  data _data_(keep=memname isFolder);
44
50
  length memname $200 isFolder 8;
45
- fid=dopen("&fname1");
51
+ fid=dopen("&f1");
46
52
  if fid=0 then stop;
47
53
  memcount=dnum(fid);
48
54
  do i=1 to memcount;
@@ -53,16 +59,32 @@ data _data_(keep=memname isFolder);
53
59
  end;
54
60
  rc=dclose(fid);
55
61
  run;
56
- filename &fname1 clear;
62
+
63
+ filename &f2 temp;
57
64
 
58
65
  /* loop through each entry and either create the subfolder or extract member */
59
66
  data _null_;
60
67
  set &syslast;
68
+ file &f2;
61
69
  if isFolder then call execute('%mf_mkdir(&outdir/'!!memname!!')');
62
- else call execute('filename &fname2 zip &ziploc member='
63
- !!quote(trim(memname))!!';filename &fname3 "&outdir/'
64
- !!trim(memname)!!'" recfm=n;data _null_; rc=fcopy("&fname2","&fname3");run;'
65
- !!'filename &fname2 clear; filename &fname3 clear;');
70
+ else do;
71
+ qname=quote(cats("&outdir/",memname));
72
+ bname=cats('(',memname,')');
73
+ put '/* hat tip: "data _null_" on SAS-L */';
74
+ put 'data _null_;';
75
+ put ' infile &f1 ' bname ' lrecl=256 recfm=F length=length eof=eof unbuf;';
76
+ put ' file ' qname ' lrecl=256 recfm=N;';
77
+ put ' input;';
78
+ put ' put _infile_ $varying256. length;';
79
+ put ' return;';
80
+ put 'eof:';
81
+ put ' stop;';
82
+ put 'run;';
83
+ end;
66
84
  run;
67
85
 
68
- %mend mp_unzip;
86
+ %inc &f2/source2;
87
+
88
+ filename &f2 clear;
89
+
90
+ %mend mp_unzip;
@@ -54,6 +54,9 @@
54
54
  @param [out] pkg= (utils) The output package in which to create the function.
55
55
  Uses a 3 part format: libref.catalog.package
56
56
 
57
+ <h4> SAS Macros </h4>
58
+ @li mf_existfunction.sas
59
+
57
60
  **/
58
61
 
59
62
  %macro mcf_stpsrv_header(wrap=NO
@@ -63,6 +66,8 @@
63
66
  ,pkg=UTILS
64
67
  )/*/STORE SOURCE*/;
65
68
 
69
+ %if %mf_existfunction(stpsrv_header)=1 %then %return;
70
+
66
71
  %if &wrap=YES %then %do;
67
72
  proc fcmp outcat=&lib..&cat..&pkg;
68
73
  %end;
package/package.json CHANGED
@@ -35,5 +35,8 @@
35
35
  "devDependencies": {
36
36
  "@sasjs/cli": "^2.39.0"
37
37
  },
38
- "version": "2.54.1"
38
+ "dependencies": {
39
+ "ts-loader": "^9.2.6"
40
+ },
41
+ "version": "2.55.0"
39
42
  }
@@ -91,7 +91,7 @@
91
91
 
92
92
  %else %if &action=ARR or &action=OBJ %then %do;
93
93
  %mp_jsonout(&action,&ds,dslabel=&dslabel,fmt=&fmt,jref=&fref
94
- ,engine=&jsonengine,dbg=%str(&_debug)
94
+ ,engine=DATASTEP,dbg=%str(&_debug)
95
95
  )
96
96
  %end;
97
97
  %else %if &action=CLOSE %then %do;
@@ -124,8 +124,8 @@
124
124
  put " ""&wt"" : {";
125
125
  put '"nlobs":' nlobs;
126
126
  put ',"nvars":' nvars;
127
- %mp_jsonout(OBJ,&tempds,jref=&fref,dslabel=colattrs,engine=&jsonengine)
128
- %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=&jsonengine)
127
+ %mp_jsonout(OBJ,&tempds,jref=&fref,dslabel=colattrs,engine=DATASTEP)
128
+ %mp_jsonout(OBJ,&wt,jref=&fref,dslabel=first10rows,engine=DATASTEP)
129
129
  data _null_; file &fref mod encoding='utf-8';
130
130
  put "}";
131
131
  %end;
@@ -159,6 +159,7 @@
159
159
  autoexec=quote(trim(getoption('autoexec')));
160
160
  put ',"AUTOEXEC" : ' autoexec;
161
161
  memsize="%sysfunc(INPUTN(%sysfunc(getoption(memsize)), best.),sizekmg.)";
162
+ memsize=quote(cats(memsize));
162
163
  put ',"MEMSIZE" : ' memsize;
163
164
  put "}" @;
164
165
  %if %str(&_debug) ge 131 %then %do;