@sasjs/core 4.63.0 → 4.64.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 +1 -1
- package/base/mp_assert.sas +1 -0
- package/base/mp_assertscope.sas +2 -1
- package/base/mp_init.sas +2 -1
- package/package.json +1 -1
- package/viya/mfv_existsashdat.sas +8 -9
- package/viya/mfv_getcaslib.sas +37 -0
- package/viya/mv_castabload.sas +207 -0
- package/viya/mv_castabsave.sas +192 -0
package/README.md
CHANGED
|
@@ -201,7 +201,7 @@ When contributing to this library, it is therefore important to ensure that all
|
|
|
201
201
|
- 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.
|
|
202
202
|
- 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;`
|
|
203
203
|
- Where global macro variables are absolutely necessary, they should make use of `&sasjs_prefix` - see mp_init.sas
|
|
204
|
-
- The use of `quit;` for `proc sql` is
|
|
204
|
+
- The use of `quit;` for `proc sql` is essential, to avoid `WARNING: You cannot disconnect or terminate session XXXX until the procedure completes.` when terminating CAS sessions in Viya.
|
|
205
205
|
- Use [sasjs lint](https://github.com/sasjs/lint)!
|
|
206
206
|
|
|
207
207
|
## General Notes
|
package/base/mp_assert.sas
CHANGED
package/base/mp_assertscope.sas
CHANGED
|
@@ -92,6 +92,7 @@
|
|
|
92
92
|
from dictionary.macros
|
|
93
93
|
where scope="&scope" and upcase(name) not in (%mf_getquotedstr(&ilist))
|
|
94
94
|
order by name,offset;
|
|
95
|
+
quit;
|
|
95
96
|
%end;
|
|
96
97
|
%else %if &action=COMPARE %then %do;
|
|
97
98
|
|
|
@@ -129,7 +130,6 @@
|
|
|
129
130
|
%let test_comments=%str(Mod:(&mod) Add:(&add) Del:(&del));
|
|
130
131
|
%end;
|
|
131
132
|
|
|
132
|
-
|
|
133
133
|
data ;
|
|
134
134
|
length test_description $256 test_result $4 test_comments $256;
|
|
135
135
|
test_description=symget('desc');
|
|
@@ -142,6 +142,7 @@
|
|
|
142
142
|
run;
|
|
143
143
|
proc sql;
|
|
144
144
|
drop table &ds;
|
|
145
|
+
quit;
|
|
145
146
|
%end;
|
|
146
147
|
|
|
147
148
|
%mend mp_assertscope;
|
package/base/mp_init.sas
CHANGED
|
@@ -41,8 +41,9 @@
|
|
|
41
41
|
&prefix._INIT_NUM /* initialisation time as numeric */
|
|
42
42
|
&prefix._INIT_DTTM /* initialisation time in E8601DT26.6 format */
|
|
43
43
|
&prefix.WORK /* avoid typing %sysfunc(pathname(work)) every time */
|
|
44
|
+
&prefix.PROCESSMODE
|
|
45
|
+
&prefix._STPSRV_HEADER_LOC
|
|
44
46
|
;
|
|
45
|
-
|
|
46
47
|
%let sasjs_prefix=&prefix;
|
|
47
48
|
|
|
48
49
|
data _null_;
|
package/package.json
CHANGED
|
@@ -6,12 +6,12 @@
|
|
|
6
6
|
%if %mfv_existsashdat(libds=casuser.sometable) %then %put yes it does!;
|
|
7
7
|
|
|
8
8
|
The function uses `dosubl()` to run the `table.fileinfo` action, for the
|
|
9
|
-
specified library, filtering for `*.sashdat` tables.
|
|
10
|
-
in a WORK table (&outprefix._&lib). If that table already exists, it is
|
|
11
|
-
queried instead, to avoid the dosubl() performance hit.
|
|
9
|
+
specified library, filtering for `*.sashdat` tables.
|
|
12
10
|
|
|
13
|
-
|
|
14
|
-
|
|
11
|
+
Results are cached in a WORK table (&outprefix._&lib). If that table
|
|
12
|
+
already exists it is queried directly to avoid the dosubl() overhead.
|
|
13
|
+
To force a rescan, use a new `&outprefix` value or delete the cache
|
|
14
|
+
table before calling.
|
|
15
15
|
|
|
16
16
|
@param [in] libds library.dataset
|
|
17
17
|
@param [out] outprefix= (work.mfv_existsashdat)
|
|
@@ -24,13 +24,12 @@
|
|
|
24
24
|
@author Mathieu Blauw
|
|
25
25
|
**/
|
|
26
26
|
|
|
27
|
-
%macro mfv_existsashdat(libds,outprefix=work.mfv_existsashdat
|
|
28
|
-
);
|
|
27
|
+
%macro mfv_existsashdat(libds,outprefix=work.mfv_existsashdat);
|
|
29
28
|
%local rc dsid name lib ds;
|
|
30
29
|
%let lib=%upcase(%scan(&libds,1,'.'));
|
|
31
30
|
%let ds=%upcase(%scan(&libds,-1,'.'));
|
|
32
31
|
|
|
33
|
-
/* if table does not exist,
|
|
32
|
+
/* if cache table does not exist, build it */
|
|
34
33
|
%if %sysfunc(exist(&outprefix._&lib)) ne 1 %then %do;
|
|
35
34
|
%let rc=%sysfunc(dosubl(%nrstr(
|
|
36
35
|
/* Read in table list (once per &lib per session) */
|
|
@@ -41,7 +40,7 @@
|
|
|
41
40
|
quit;
|
|
42
41
|
/* Only keep name, without file extension */
|
|
43
42
|
data &outprefix._&lib;
|
|
44
|
-
set &outprefix._&lib(where=(Name like '%.
|
|
43
|
+
set &outprefix._&lib(where=(upcase(Name) like '%.SASHDAT') keep=Name);
|
|
45
44
|
Name=upcase(scan(Name,1,'.'));
|
|
46
45
|
run;
|
|
47
46
|
)));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file mfv_getcaslib.sas
|
|
3
|
+
@brief Returns the CAS caslib name for a given SAS libref
|
|
4
|
+
@details Pure macro function. Reads sashelp.vlibnam and returns
|
|
5
|
+
the sysvalue where sysname='Caslib' for the given libref. This
|
|
6
|
+
is useful when the caslib name and libref name may differ.
|
|
7
|
+
|
|
8
|
+
Usage:
|
|
9
|
+
|
|
10
|
+
%put %mfv_getcaslib(lib=PUBLIC);
|
|
11
|
+
|
|
12
|
+
@param [in] lib SAS libref for which to return the CAS caslib name
|
|
13
|
+
|
|
14
|
+
@return Returns the CAS caslib name, or empty string if not found
|
|
15
|
+
|
|
16
|
+
**/
|
|
17
|
+
|
|
18
|
+
%macro mfv_getcaslib(lib);
|
|
19
|
+
|
|
20
|
+
%local dsid rc result;
|
|
21
|
+
|
|
22
|
+
%let dsid=%sysfunc(open(sashelp.vlibnam(
|
|
23
|
+
where=(libname="%upcase(&lib)" and sysname="Caslib")
|
|
24
|
+
)));
|
|
25
|
+
|
|
26
|
+
%if &dsid %then %do;
|
|
27
|
+
%let rc=%sysfunc(fetch(&dsid));
|
|
28
|
+
%if &rc=0 %then
|
|
29
|
+
%let result=%sysfunc(
|
|
30
|
+
getvarc(&dsid,%sysfunc(varnum(&dsid,SYSVALUE)))
|
|
31
|
+
);
|
|
32
|
+
%let rc=%sysfunc(close(&dsid));
|
|
33
|
+
%end;
|
|
34
|
+
|
|
35
|
+
&result
|
|
36
|
+
|
|
37
|
+
%mend mfv_getcaslib;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file mv_castabload.sas
|
|
3
|
+
@brief Checks if a CAS table is loaded; if not, loads and promotes it
|
|
4
|
+
@details Runs in SPRE against an active CAS session. Accepts a
|
|
5
|
+
SAS libref, derives the CAS caslib and session UUID from
|
|
6
|
+
sashelp.vlibnam, then checks whether the table is already
|
|
7
|
+
in-memory. If not, locates the owning CAS server via the
|
|
8
|
+
casManagement REST API, queries the table endpoint to discover
|
|
9
|
+
the source file and caslib, then loads and promotes the table.
|
|
10
|
+
|
|
11
|
+
A CAS session must already be established by the caller, eg:
|
|
12
|
+
|
|
13
|
+
cas mysess;
|
|
14
|
+
libname mylib cas caslib=Public;
|
|
15
|
+
%mv_castabload(lib=mylib, table=BASEBALL)
|
|
16
|
+
|
|
17
|
+
@param [in] lib= SAS libref for the CAS caslib
|
|
18
|
+
@param [in] table= Name of the CAS table to load
|
|
19
|
+
@param [in] mdebug= (0) Set to 1 to enable verbose logging:
|
|
20
|
+
- echoes resolved parameters
|
|
21
|
+
- prints tableExists result
|
|
22
|
+
- enables mprint/notes during PROC calls
|
|
23
|
+
|
|
24
|
+
<h4> SAS Macros </h4>
|
|
25
|
+
@li mf_getplatform.sas
|
|
26
|
+
@li mf_getuniquefileref.sas
|
|
27
|
+
@li mf_getuniquelibref.sas
|
|
28
|
+
@li mp_abort.sas
|
|
29
|
+
|
|
30
|
+
**/
|
|
31
|
+
|
|
32
|
+
%macro mv_castabload(
|
|
33
|
+
lib=
|
|
34
|
+
,table=
|
|
35
|
+
,mdebug=0
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
%local _sysopts base_uri caslib uuid server
|
|
39
|
+
srcfile srccaslib fname1 libref1 ftmp i _svcount _exists;
|
|
40
|
+
%let _sysopts=%sysfunc(getoption(mprint)) %sysfunc(getoption(notes));
|
|
41
|
+
|
|
42
|
+
/* ---- input validation -------------------------------------------------- */
|
|
43
|
+
%mp_abort(
|
|
44
|
+
iftrue=("&lib"="" or "&table"=""),
|
|
45
|
+
msg=%str(lib= and table= are required)
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
%if &mdebug=1 %then %do;
|
|
49
|
+
%put &=lib;
|
|
50
|
+
%put &=table;
|
|
51
|
+
options mprint notes;
|
|
52
|
+
%end;
|
|
53
|
+
|
|
54
|
+
/* ---- derive caslib and session UUID from sashelp.vlibnam --------------- */
|
|
55
|
+
data _null_;
|
|
56
|
+
set sashelp.vlibnam(
|
|
57
|
+
where=(libname="%upcase(&lib)"
|
|
58
|
+
and sysname in ("Caslib","Session UUID"))
|
|
59
|
+
);
|
|
60
|
+
if sysname="Caslib" then call symputx('caslib',sysvalue,'L');
|
|
61
|
+
else call symputx('uuid',sysvalue,'L');
|
|
62
|
+
%if &mdebug=1 %then %do;
|
|
63
|
+
putlog sysname sysvalue;
|
|
64
|
+
%end;
|
|
65
|
+
run;
|
|
66
|
+
|
|
67
|
+
%mp_abort(
|
|
68
|
+
iftrue=("&caslib"=""),
|
|
69
|
+
msg=%str(&lib is not an assigned CAS libref)
|
|
70
|
+
)
|
|
71
|
+
|
|
72
|
+
%mp_abort(
|
|
73
|
+
iftrue=("&uuid"=""),
|
|
74
|
+
msg=%str(No session UUID found for libref &lib)
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
/* ---- existence check --------------------------------------------------- */
|
|
78
|
+
proc cas;
|
|
79
|
+
table.tableExists result=r /
|
|
80
|
+
caslib="&caslib"
|
|
81
|
+
name="&table";
|
|
82
|
+
%if &mdebug=1 %then %do;
|
|
83
|
+
print r;
|
|
84
|
+
%end;
|
|
85
|
+
if r.exists > 0 then call symputx('_exists', '1', 'L');
|
|
86
|
+
else call symputx('_exists', '0', 'L');
|
|
87
|
+
quit;
|
|
88
|
+
|
|
89
|
+
/* ---- already loaded: skip ---------------------------------------------- */
|
|
90
|
+
%if &_exists=1 %then %do;
|
|
91
|
+
%put NOTE: Table &caslib..&table already loaded - skipping;
|
|
92
|
+
%return;
|
|
93
|
+
%end;
|
|
94
|
+
|
|
95
|
+
/* ---- get list of CAS servers ----------------------------------------- */
|
|
96
|
+
%let base_uri=%mf_getplatform(VIYARESTAPI);
|
|
97
|
+
%let fname1=%mf_getuniquefileref();
|
|
98
|
+
%let libref1=%mf_getuniquelibref();
|
|
99
|
+
|
|
100
|
+
proc http method='GET' out=&fname1 oauth_bearer=sas_services
|
|
101
|
+
url="&base_uri/casManagement/servers";
|
|
102
|
+
run;
|
|
103
|
+
|
|
104
|
+
%mp_abort(
|
|
105
|
+
iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200),
|
|
106
|
+
msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
libname &libref1 JSON fileref=&fname1;
|
|
110
|
+
|
|
111
|
+
data _null_;
|
|
112
|
+
set &libref1..items;
|
|
113
|
+
call symputx(cats('_sv_', _n_), name, 'L');
|
|
114
|
+
call symputx('_svcount', _n_, 'L');
|
|
115
|
+
run;
|
|
116
|
+
|
|
117
|
+
libname &libref1 clear;
|
|
118
|
+
filename &fname1 clear;
|
|
119
|
+
|
|
120
|
+
/* ---- find which server owns this session ------------------------------ */
|
|
121
|
+
%do i=1 %to &_svcount;
|
|
122
|
+
%if "&server"="" %then %do;
|
|
123
|
+
%if &mdebug=1 %then %put checking server: &&_sv_&i;
|
|
124
|
+
%let ftmp=%mf_getuniquefileref();
|
|
125
|
+
proc http method='GET' out=&ftmp oauth_bearer=sas_services
|
|
126
|
+
url="&base_uri/casManagement/servers/&&_sv_&i/sessions/&uuid";
|
|
127
|
+
run;
|
|
128
|
+
%if &SYS_PROCHTTP_STATUS_CODE=200
|
|
129
|
+
%then %let server=&&_sv_&i;
|
|
130
|
+
filename &ftmp clear;
|
|
131
|
+
%end;
|
|
132
|
+
%end;
|
|
133
|
+
|
|
134
|
+
%mp_abort(
|
|
135
|
+
iftrue=("&server"=""),
|
|
136
|
+
msg=%str(Could not find owning server for CAS session &uuid)
|
|
137
|
+
)
|
|
138
|
+
|
|
139
|
+
%if &mdebug=1 %then %put &=server;
|
|
140
|
+
|
|
141
|
+
/* ---- discover source file from REST endpoint -------------------------- */
|
|
142
|
+
%let fname1=%mf_getuniquefileref();
|
|
143
|
+
%let libref1=%mf_getuniquelibref();
|
|
144
|
+
|
|
145
|
+
proc http method='GET' out=&fname1 oauth_bearer=sas_services
|
|
146
|
+
url="&base_uri/casManagement/servers/&server/caslibs/&caslib/tables/&table";
|
|
147
|
+
run;
|
|
148
|
+
|
|
149
|
+
%if &mdebug=1 %then %do;
|
|
150
|
+
%put &=SYS_PROCHTTP_STATUS_CODE &=SYS_PROCHTTP_STATUS_PHRASE;
|
|
151
|
+
data _null_;
|
|
152
|
+
infile &fname1;
|
|
153
|
+
input;
|
|
154
|
+
putlog _infile_;
|
|
155
|
+
run;
|
|
156
|
+
%end;
|
|
157
|
+
|
|
158
|
+
%mp_abort(
|
|
159
|
+
iftrue=(&SYS_PROCHTTP_STATUS_CODE=404),
|
|
160
|
+
msg=%str(&caslib..&table not found - is a source file registered?)
|
|
161
|
+
)
|
|
162
|
+
%mp_abort(
|
|
163
|
+
iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200),
|
|
164
|
+
msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
libname &libref1 JSON fileref=&fname1;
|
|
168
|
+
|
|
169
|
+
data _null_;
|
|
170
|
+
set &libref1..tablereference;
|
|
171
|
+
call symputx('srcfile', sourceTableName, 'L');
|
|
172
|
+
call symputx('srccaslib', sourceCaslibName, 'L');
|
|
173
|
+
stop;
|
|
174
|
+
run;
|
|
175
|
+
|
|
176
|
+
libname &libref1 clear;
|
|
177
|
+
filename &fname1 clear;
|
|
178
|
+
|
|
179
|
+
%mp_abort(
|
|
180
|
+
iftrue=("&srcfile"="" or "&srccaslib"=""),
|
|
181
|
+
msg=%str(No sourceTableName/sourceCaslibName for &caslib..&table)
|
|
182
|
+
)
|
|
183
|
+
|
|
184
|
+
%if &mdebug=1 %then %put &=srcfile &=srccaslib;
|
|
185
|
+
|
|
186
|
+
/* ---- load from discovered source -------------------------------------- */
|
|
187
|
+
proc casutil;
|
|
188
|
+
load casdata="&srcfile"
|
|
189
|
+
incaslib="&srccaslib"
|
|
190
|
+
casout="&table"
|
|
191
|
+
outcaslib="&caslib"
|
|
192
|
+
promote;
|
|
193
|
+
quit;
|
|
194
|
+
|
|
195
|
+
%mp_abort(
|
|
196
|
+
iftrue=(&syscc ne 0),
|
|
197
|
+
msg=%str(Load failed for &caslib..&table)
|
|
198
|
+
)
|
|
199
|
+
|
|
200
|
+
%put NOTE: Table &caslib..&table loaded and promoted from &srcfile;
|
|
201
|
+
|
|
202
|
+
/* ---- restore options --------------------------------------------------- */
|
|
203
|
+
%if &mdebug=1 %then %do;
|
|
204
|
+
options &_sysopts;
|
|
205
|
+
%end;
|
|
206
|
+
|
|
207
|
+
%mend mv_castabload;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
@file mv_castabsave.sas
|
|
3
|
+
@brief Saves an in-memory CAS table back to persistent storage
|
|
4
|
+
@details Runs in SPRE against an active CAS session. Accepts a
|
|
5
|
+
SAS libref, derives the CAS caslib and session UUID from
|
|
6
|
+
sashelp.vlibnam, locates the owning CAS server via the
|
|
7
|
+
casManagement REST API, then queries the table endpoint to
|
|
8
|
+
discover the original source file and saves back to that path.
|
|
9
|
+
CASUTIL infers the file type from the output file extension.
|
|
10
|
+
|
|
11
|
+
A CAS session must already be established by the caller, eg:
|
|
12
|
+
|
|
13
|
+
cas mysess;
|
|
14
|
+
libname mylib cas caslib=Public;
|
|
15
|
+
%mv_castabsave(lib=mylib, table=BASEBALL)
|
|
16
|
+
|
|
17
|
+
@param [in] lib= SAS libref for the CAS caslib
|
|
18
|
+
@param [in] table= Name of the in-memory CAS table to save
|
|
19
|
+
@param [in] mdebug= (0) Set to 1 to enable verbose logging:
|
|
20
|
+
- echoes resolved parameters
|
|
21
|
+
- prints HTTP response body
|
|
22
|
+
- enables mprint/notes during PROC calls
|
|
23
|
+
|
|
24
|
+
<h4> SAS Macros </h4>
|
|
25
|
+
@li mf_getplatform.sas
|
|
26
|
+
@li mf_getuniquefileref.sas
|
|
27
|
+
@li mf_getuniquelibref.sas
|
|
28
|
+
@li mp_abort.sas
|
|
29
|
+
|
|
30
|
+
**/
|
|
31
|
+
|
|
32
|
+
%macro mv_castabsave(
|
|
33
|
+
lib=
|
|
34
|
+
,table=
|
|
35
|
+
,mdebug=0
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
%local _sysopts base_uri caslib uuid server
|
|
39
|
+
srcfile srccaslib fname1 libref1 ftmp i _svcount;
|
|
40
|
+
%let _sysopts=%sysfunc(getoption(mprint)) %sysfunc(getoption(notes));
|
|
41
|
+
|
|
42
|
+
/* ---- input validation -------------------------------------------------- */
|
|
43
|
+
%mp_abort(
|
|
44
|
+
iftrue=("&lib"="" or "&table"=""),
|
|
45
|
+
msg=%str(lib= and table= are required)
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
%if &mdebug=1 %then %do;
|
|
49
|
+
%put &=lib;
|
|
50
|
+
%put &=table;
|
|
51
|
+
options mprint notes;
|
|
52
|
+
%end;
|
|
53
|
+
|
|
54
|
+
/* ---- derive caslib and session UUID from sashelp.vlibnam --------------- */
|
|
55
|
+
data _null_;
|
|
56
|
+
set sashelp.vlibnam(
|
|
57
|
+
where=(libname="%upcase(&lib)"
|
|
58
|
+
and sysname in ("Caslib","Session UUID"))
|
|
59
|
+
);
|
|
60
|
+
if sysname="Caslib" then call symputx('caslib',sysvalue,'L');
|
|
61
|
+
else call symputx('uuid',sysvalue,'L');
|
|
62
|
+
run;
|
|
63
|
+
|
|
64
|
+
%mp_abort(
|
|
65
|
+
iftrue=("&caslib"=""),
|
|
66
|
+
msg=%str(&lib is not an assigned CAS libref)
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
%mp_abort(
|
|
70
|
+
iftrue=("&uuid"=""),
|
|
71
|
+
msg=%str(No session UUID found for libref &lib)
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
%if &mdebug=1 %then %do;
|
|
75
|
+
%put &=caslib;
|
|
76
|
+
%put &=uuid;
|
|
77
|
+
%end;
|
|
78
|
+
|
|
79
|
+
%let base_uri=%mf_getplatform(VIYARESTAPI);
|
|
80
|
+
|
|
81
|
+
/* ---- get list of CAS servers ------------------------------------------- */
|
|
82
|
+
%let fname1=%mf_getuniquefileref();
|
|
83
|
+
%let libref1=%mf_getuniquelibref();
|
|
84
|
+
|
|
85
|
+
proc http method='GET' out=&fname1 oauth_bearer=sas_services
|
|
86
|
+
url="&base_uri/casManagement/servers";
|
|
87
|
+
run;
|
|
88
|
+
|
|
89
|
+
%mp_abort(
|
|
90
|
+
iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200),
|
|
91
|
+
msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
libname &libref1 JSON fileref=&fname1;
|
|
95
|
+
|
|
96
|
+
data _null_;
|
|
97
|
+
set &libref1..items;
|
|
98
|
+
call symputx(cats('_sv_', _n_), name, 'L');
|
|
99
|
+
call symputx('_svcount', _n_, 'L');
|
|
100
|
+
run;
|
|
101
|
+
|
|
102
|
+
libname &libref1 clear;
|
|
103
|
+
filename &fname1 clear;
|
|
104
|
+
|
|
105
|
+
/* ---- find which server owns this session ------------------------------- */
|
|
106
|
+
%do i=1 %to &_svcount;
|
|
107
|
+
%if "&server"="" %then %do;
|
|
108
|
+
%if &mdebug=1 %then %put checking server: &&_sv_&i;
|
|
109
|
+
%let ftmp=%mf_getuniquefileref();
|
|
110
|
+
proc http method='GET' out=&ftmp oauth_bearer=sas_services
|
|
111
|
+
url="&base_uri/casManagement/servers/&&_sv_&i/sessions/&uuid";
|
|
112
|
+
run;
|
|
113
|
+
%if &SYS_PROCHTTP_STATUS_CODE=200
|
|
114
|
+
%then %let server=&&_sv_&i;
|
|
115
|
+
filename &ftmp clear;
|
|
116
|
+
%end;
|
|
117
|
+
%end;
|
|
118
|
+
|
|
119
|
+
%mp_abort(
|
|
120
|
+
iftrue=("&server"=""),
|
|
121
|
+
msg=%str(Could not find owning server for CAS session &uuid)
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
%if &mdebug=1 %then %put &=server;
|
|
125
|
+
|
|
126
|
+
/* ---- discover srcfile from REST endpoint ------------------------------- */
|
|
127
|
+
%let fname1=%mf_getuniquefileref();
|
|
128
|
+
%let libref1=%mf_getuniquelibref();
|
|
129
|
+
|
|
130
|
+
proc http method='GET' out=&fname1 oauth_bearer=sas_services
|
|
131
|
+
url="&base_uri/casManagement/servers/&server/caslibs/&caslib/tables/&table";
|
|
132
|
+
run;
|
|
133
|
+
|
|
134
|
+
%if &mdebug=1 %then %do;
|
|
135
|
+
%put &=SYS_PROCHTTP_STATUS_CODE &=SYS_PROCHTTP_STATUS_PHRASE;
|
|
136
|
+
data _null_;
|
|
137
|
+
infile &fname1;
|
|
138
|
+
input;
|
|
139
|
+
putlog _infile_;
|
|
140
|
+
run;
|
|
141
|
+
%end;
|
|
142
|
+
|
|
143
|
+
%mp_abort(
|
|
144
|
+
iftrue=(&SYS_PROCHTTP_STATUS_CODE=404),
|
|
145
|
+
msg=%str(&caslib..&table not found - is it loaded in memory?)
|
|
146
|
+
)
|
|
147
|
+
%mp_abort(
|
|
148
|
+
iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200),
|
|
149
|
+
msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
libname &libref1 JSON fileref=&fname1;
|
|
153
|
+
|
|
154
|
+
data _null_;
|
|
155
|
+
set &libref1..tablereference;
|
|
156
|
+
call symputx('srcfile', sourceTableName, 'L');
|
|
157
|
+
call symputx('srccaslib', sourceCaslibName, 'L');
|
|
158
|
+
stop;
|
|
159
|
+
run;
|
|
160
|
+
|
|
161
|
+
libname &libref1 clear;
|
|
162
|
+
filename &fname1 clear;
|
|
163
|
+
|
|
164
|
+
%mp_abort(
|
|
165
|
+
iftrue=("&srcfile"="" or "&srccaslib"=""),
|
|
166
|
+
msg=%str(No sourceTableName/sourceCaslibName for &caslib..&table)
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
%if &mdebug=1 %then %put &=srcfile;
|
|
170
|
+
|
|
171
|
+
/* ---- save to disk ------------------------------------------------------- */
|
|
172
|
+
proc casutil;
|
|
173
|
+
save casdata="&table"
|
|
174
|
+
incaslib="&caslib"
|
|
175
|
+
casout="&srcfile"
|
|
176
|
+
outcaslib="&srccaslib"
|
|
177
|
+
replace;
|
|
178
|
+
quit;
|
|
179
|
+
|
|
180
|
+
%mp_abort(
|
|
181
|
+
iftrue=(&syscc ne 0),
|
|
182
|
+
msg=%str(Save failed for &caslib..&table)
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
%put NOTE: Table &caslib..&table saved to &srcfile;
|
|
186
|
+
|
|
187
|
+
/* ---- restore options --------------------------------------------------- */
|
|
188
|
+
%if &mdebug=1 %then %do;
|
|
189
|
+
options &_sysopts;
|
|
190
|
+
%end;
|
|
191
|
+
|
|
192
|
+
%mend mv_castabsave;
|