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));
44 iftrue=(
"&lib"=
"" or
"&table"=
""),
45 msg=%str(lib= and table= are required)
48%
if &mdebug=1 %then %
do;
57 where=(libname=
"%upcase(&lib)"
58 and sysname in (
"Caslib",
"Session UUID"))
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;
68 iftrue=(
"&caslib"=
""),
69 msg=%str(&lib is not an assigned CAS libref)
74 msg=%str(No session UUID found
for libref &lib)
79 table.tableExists result=r /
82 %
if &mdebug=1 %then %
do;
85 if r.exists > 0 then call symputx(
'_exists',
'1',
'L');
86 else call symputx(
'_exists',
'0',
'L');
90%
if &_exists=1 %then %
do;
91 %put NOTE: Table &caslib..&table already loaded - skipping;
96%let base_uri=%mf_getplatform(VIYARESTAPI);
97%let fname1=%mf_getuniquefileref();
98%let libref1=%mf_getuniquelibref();
100proc http method=
'GET' out=&fname1 oauth_bearer=sas_services
101 url=
"&base_uri/casManagement/servers";
105 iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200),
106 msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
109libname &libref1 JSON fileref=&fname1;
113 call symputx(cats(
'_sv_', _n_), name,
'L');
114 call symputx(
'_svcount', _n_,
'L');
117libname &libref1 clear;
118filename &fname1 clear;
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";
128 %
if &SYS_PROCHTTP_STATUS_CODE=200
129 %then %let server=&&_sv_&i;
130 filename &ftmp clear;
135 iftrue=(
"&server"=
""),
136 msg=%str(Could not find owning server
for CAS session &uuid)
139%
if &mdebug=1 %then %put &=server;
142%let fname1=%mf_getuniquefileref();
143%let libref1=%mf_getuniquelibref();
145proc http method=
'GET' out=&fname1 oauth_bearer=sas_services
146 url=
"&base_uri/casManagement/servers/&server/caslibs/&caslib/tables/&table";
149%
if &mdebug=1 %then %
do;
150 %put &=SYS_PROCHTTP_STATUS_CODE &=SYS_PROCHTTP_STATUS_PHRASE;
159 iftrue=(&SYS_PROCHTTP_STATUS_CODE=404),
160 msg=%str(&caslib..&table not found - is a source file registered?)
163 iftrue=(&SYS_PROCHTTP_STATUS_CODE ne 200),
164 msg=%str(&SYS_PROCHTTP_STATUS_CODE &SYS_PROCHTTP_STATUS_PHRASE)
167libname &libref1 JSON fileref=&fname1;
170 set &libref1..tablereference;
171 call symputx(
'srcfile', sourceTableName,
'L');
172 call symputx(
'srccaslib', sourceCaslibName,
'L');
176libname &libref1 clear;
177filename &fname1 clear;
180 iftrue=(
"&srcfile"=
"" or
"&srccaslib"=
""),
181 msg=%str(No sourceTableName/sourceCaslibName
for &caslib..&table)
184%
if &mdebug=1 %then %put &=srcfile &=srccaslib;
188 load casdata=
"&srcfile"
189 incaslib=
"&srccaslib"
196 iftrue=(&syscc ne 0),
197 msg=%str(Load failed
for &caslib..&table)
200%put NOTE: Table &caslib..&table loaded and promoted from &srcfile;
203%
if &mdebug=1 %then %
do;