mirror of
https://github.com/sasjs/core.git
synced 2026-01-05 00:20:05 +00:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ac46489f11 | |||
|
|
5e45701e74 | ||
|
|
8caaacd9f0 | ||
|
|
91983e0a91 | ||
|
|
7b72f0ac94 | ||
|
|
3eae34d8b7 | ||
|
|
58358c916d | ||
|
|
578ef26cd5 | ||
|
|
33189743cd | ||
|
|
459beff4fa |
137
all.sas
137
all.sas
@@ -510,6 +510,7 @@ options noquotelenmax;
|
|||||||
|
|
||||||
<h4> Dependencies </h4>
|
<h4> Dependencies </h4>
|
||||||
@li mf_mval.sas
|
@li mf_mval.sas
|
||||||
|
@li mf_trimstr.sas
|
||||||
|
|
||||||
@version 9.4 / 3.4
|
@version 9.4 / 3.4
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
@@ -555,7 +556,7 @@ options noquotelenmax;
|
|||||||
%else 0;
|
%else 0;
|
||||||
%end;
|
%end;
|
||||||
%else %if &switch=VIYARESTAPI %then %do;
|
%else %if &switch=VIYARESTAPI %then %do;
|
||||||
%sysfunc(getoption(servicesbaseurl))
|
%mf_trimstr(%sysfunc(getoption(servicesbaseurl)),/)
|
||||||
%end;
|
%end;
|
||||||
%mend;/**
|
%mend;/**
|
||||||
@file
|
@file
|
||||||
@@ -1290,6 +1291,54 @@ Usage:
|
|||||||
%macro mf_nobs(libds
|
%macro mf_nobs(libds
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
%mf_getattrn(&libds,NLOBS)
|
%mf_getattrn(&libds,NLOBS)
|
||||||
|
%mend;/**
|
||||||
|
@file mf_trimstr.sas
|
||||||
|
@brief Removes character(s) from the end, if they exist
|
||||||
|
@details If the designated characters exist at the end of the string, they
|
||||||
|
are removed
|
||||||
|
|
||||||
|
%put %mf_trimstr(/blah/,/); * /blah;
|
||||||
|
%put %mf_trimstr(/blah/,h); * /blah/;
|
||||||
|
%put %mf_trimstr(/blah/,h/);* /bla;
|
||||||
|
|
||||||
|
<h4> Dependencies </h4>
|
||||||
|
|
||||||
|
|
||||||
|
@param basestr The string to be modified
|
||||||
|
@param trimstr The string to be removed from the end of `basestr`, if it exists
|
||||||
|
|
||||||
|
@return output returns result with the value of `trimstr` removed from the end
|
||||||
|
|
||||||
|
|
||||||
|
@version 9.2
|
||||||
|
@author Allan Bowe
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
%macro mf_trimstr(basestr,trimstr);
|
||||||
|
%local baselen trimlen trimval;
|
||||||
|
|
||||||
|
/* return if basestr is shorter than trimstr (or 0) */
|
||||||
|
%let baselen=%length(%superq(basestr));
|
||||||
|
%let trimlen=%length(%superq(trimstr));
|
||||||
|
%if &baselen < &trimlen or &baselen=0 %then %return;
|
||||||
|
|
||||||
|
/* obtain the characters from the end of basestr */
|
||||||
|
%let trimval=%qsubstr(%superq(basestr)
|
||||||
|
,%length(%superq(basestr))-&trimlen+1
|
||||||
|
,&trimlen);
|
||||||
|
|
||||||
|
/* compare and if matching, chop it off! */
|
||||||
|
%if %superq(basestr)=%superq(trimstr) %then %do;
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
|
%else %if %superq(trimval)=%superq(trimstr) %then %do;
|
||||||
|
%qsubstr(%superq(basestr),1,%length(%superq(basestr))-&trimlen)
|
||||||
|
%end;
|
||||||
|
%else %do;
|
||||||
|
&basestr
|
||||||
|
%end;
|
||||||
|
|
||||||
%mend;/**
|
%mend;/**
|
||||||
@file
|
@file
|
||||||
@brief Creates a Unique ID based on system time in a friendly format
|
@brief Creates a Unique ID based on system time in a friendly format
|
||||||
@@ -1436,6 +1485,12 @@ Usage:
|
|||||||
the particulars of an environment. For instance, can stream custom
|
the particulars of an environment. For instance, can stream custom
|
||||||
results back to the client in an STP Web App context, or completely stop
|
results back to the client in an STP Web App context, or completely stop
|
||||||
in the case of a batch run.
|
in the case of a batch run.
|
||||||
|
|
||||||
|
Using SAS Abort Cancel mechanisms can cause hung sessions in some Stored Process
|
||||||
|
environments. This macro takes a unique approach - we set the SAS syscc to 0,
|
||||||
|
run `stpsrvset('program error', 0)` (if SAS 9) and then - we open a macro
|
||||||
|
but don't close it! This provides a graceful abort for SAS web services in all
|
||||||
|
web enabled environments.
|
||||||
|
|
||||||
@param mac= to contain the name of the calling macro
|
@param mac= to contain the name of the calling macro
|
||||||
@param msg= message to be returned
|
@param msg= message to be returned
|
||||||
@@ -1496,8 +1551,15 @@ Usage:
|
|||||||
%end;
|
%end;
|
||||||
|
|
||||||
%if %symexist(SYS_JES_JOB_URI) %then %do;
|
%if %symexist(SYS_JES_JOB_URI) %then %do;
|
||||||
/* refer web service output to file service in one hit */
|
/* setup webout */
|
||||||
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json";
|
OPTIONS NOBOMFILE;
|
||||||
|
%if "X&SYS_JES_JOB_URI.X"="XX" %then %do;
|
||||||
|
filename _webout temp lrecl=999999 mod;
|
||||||
|
%end;
|
||||||
|
%else %do;
|
||||||
|
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI"
|
||||||
|
name="_webout.json" lrecl=999999 mod;
|
||||||
|
%end;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
/* send response in SASjs JSON format */
|
/* send response in SASjs JSON format */
|
||||||
@@ -3658,7 +3720,7 @@ proc sort; by descending sumcols memname libname; run;
|
|||||||
@brief Searches all data in a library
|
@brief Searches all data in a library
|
||||||
@details
|
@details
|
||||||
Scans an entire library and creates a copy of any table
|
Scans an entire library and creates a copy of any table
|
||||||
containing a specific string or numeric value. Only
|
containing a specific string OR numeric value. Only
|
||||||
matching records are written out.
|
matching records are written out.
|
||||||
If both a string and numval are provided, the string
|
If both a string and numval are provided, the string
|
||||||
will take precedence.
|
will take precedence.
|
||||||
@@ -3699,9 +3761,13 @@ proc sort; by descending sumcols memname libname; run;
|
|||||||
,filter_text=%str(1=1)
|
,filter_text=%str(1=1)
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
|
|
||||||
%local table_list table table_num table colnum col start_tm vars type coltype;
|
%local table_list table table_num table colnum col start_tm check_tm vars type coltype;
|
||||||
%put process began at %sysfunc(datetime(),datetime19.);
|
%put process began at %sysfunc(datetime(),datetime19.);
|
||||||
|
|
||||||
|
%if &syscc ge 4 %then %do;
|
||||||
|
%put %str(WAR)NING: SYSCC=&syscc on macro entry;
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
|
|
||||||
%if &string = %then %let type=N;
|
%if &string = %then %let type=N;
|
||||||
%else %let type=C;
|
%else %let type=C;
|
||||||
@@ -3733,6 +3799,7 @@ proc sql
|
|||||||
%put NO COLUMNS IN &lib..&table! This will be skipped.;
|
%put NO COLUMNS IN &lib..&table! This will be skipped.;
|
||||||
%end;
|
%end;
|
||||||
%else %do;
|
%else %do;
|
||||||
|
%let check_tm=%sysfunc(datetime());
|
||||||
/* build sql statement */
|
/* build sql statement */
|
||||||
create table mpsearch.&table as select * from &lib..&table
|
create table mpsearch.&table as select * from &lib..&table
|
||||||
where %unquote(&filter_text) and
|
where %unquote(&filter_text) and
|
||||||
@@ -3743,14 +3810,19 @@ proc sql
|
|||||||
%let coltype=%mf_getvartype(&lib..&table,&col);
|
%let coltype=%mf_getvartype(&lib..&table,&col);
|
||||||
%if &type=C and &coltype=C %then %do;
|
%if &type=C and &coltype=C %then %do;
|
||||||
/* if a char column, see if it contains the string */
|
/* if a char column, see if it contains the string */
|
||||||
or (&col ? "&string")
|
or ("&col"n ? "&string")
|
||||||
%end;
|
%end;
|
||||||
%else %if &type=N and &coltype=N %then %do;
|
%else %if &type=N and &coltype=N %then %do;
|
||||||
/* if numeric match exactly */
|
/* if numeric match exactly */
|
||||||
or (&col = &numval)
|
or ("&col"n = &numval)
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
);
|
);
|
||||||
|
%put Search query for &table took %sysevalf(%sysfunc(datetime())-&check_tm) seconds;
|
||||||
|
%if &sqlrc ne 0 %then %do;
|
||||||
|
%put %str(WAR)NING: SQLRC=&sqlrc when processing &table;
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
%if %mf_nobs(mpsearch.&table)=0 %then %do;
|
%if %mf_nobs(mpsearch.&table)=0 %then %do;
|
||||||
drop table mpsearch.&table;
|
drop table mpsearch.&table;
|
||||||
%end;
|
%end;
|
||||||
@@ -7043,6 +7115,7 @@ data _null_;
|
|||||||
when ('
') rec='0A'x;
|
when ('
') rec='0A'x;
|
||||||
when ('
') rec='0D'x;
|
when ('
') rec='0D'x;
|
||||||
when ('$' ) rec='$' ;
|
when ('$' ) rec='$' ;
|
||||||
|
when ('	') rec='09'x;
|
||||||
otherwise putlog "WARNING: missing value for " entity=;
|
otherwise putlog "WARNING: missing value for " entity=;
|
||||||
end;
|
end;
|
||||||
rc =fput(fileid, substr(rec,1,1));
|
rc =fput(fileid, substr(rec,1,1));
|
||||||
@@ -7957,6 +8030,7 @@ data _null_;
|
|||||||
when ('
') rec='0A'x;
|
when ('
') rec='0A'x;
|
||||||
when ('
') rec='0D'x;
|
when ('
') rec='0D'x;
|
||||||
when ('$' ) rec='$' ;
|
when ('$' ) rec='$' ;
|
||||||
|
when ('	') rec='09'x;
|
||||||
otherwise putlog "%str(WARN)ING: missing value for " entity=;
|
otherwise putlog "%str(WARN)ING: missing value for " entity=;
|
||||||
end;
|
end;
|
||||||
rc =fput(fileid, substr(rec,1,1));
|
rc =fput(fileid, substr(rec,1,1));
|
||||||
@@ -8591,6 +8665,7 @@ run;
|
|||||||
when ('
') rec='0A'x;
|
when ('
') rec='0A'x;
|
||||||
when ('
') rec='0D'x;
|
when ('
') rec='0D'x;
|
||||||
when ('$' ) rec='$' ;
|
when ('$' ) rec='$' ;
|
||||||
|
when ('	') rec='09'x;
|
||||||
otherwise putlog "WARNING: missing value for " entity=;
|
otherwise putlog "WARNING: missing value for " entity=;
|
||||||
end;
|
end;
|
||||||
rc =fput(fileid, substr(rec,1,1));
|
rc =fput(fileid, substr(rec,1,1));
|
||||||
@@ -10555,7 +10630,7 @@ run;
|
|||||||
libname &libref1 JSON fileref=&fname1;
|
libname &libref1 JSON fileref=&fname1;
|
||||||
data _null_;
|
data _null_;
|
||||||
set &libref1..links;
|
set &libref1..links;
|
||||||
if rel='members' then call symputx('mref',quote(trim(href)),'l');
|
if rel='members' then call symputx('mref',quote("&base_uri"!!trim(href)),'l');
|
||||||
run;
|
run;
|
||||||
|
|
||||||
/* get the children */
|
/* get the children */
|
||||||
@@ -10585,7 +10660,7 @@ run;
|
|||||||
%put NOTE:;%put NOTE- &sysmacroname: &path/&name NOT FOUND;%put NOTE- ;
|
%put NOTE:;%put NOTE- &sysmacroname: &path/&name NOT FOUND;%put NOTE- ;
|
||||||
%return;
|
%return;
|
||||||
%end;
|
%end;
|
||||||
proc http method="DELETE" url="&uri" &oauth_bearer;
|
proc http method="DELETE" url="&base_uri&uri" &oauth_bearer;
|
||||||
headers
|
headers
|
||||||
%if &grant_type=authorization_code %then %do;
|
%if &grant_type=authorization_code %then %do;
|
||||||
"Authorization"="Bearer &&&access_token_var"
|
"Authorization"="Bearer &&&access_token_var"
|
||||||
@@ -10844,9 +10919,9 @@ libname &libref1 JSON fileref=&fname1;
|
|||||||
data _null_;
|
data _null_;
|
||||||
set &libref1..links;
|
set &libref1..links;
|
||||||
if rel='deleteRecursively' then
|
if rel='deleteRecursively' then
|
||||||
call symputx('href',quote(trim(href)),'l');
|
call symputx('href',quote("&base_uri"!!trim(href)),'l');
|
||||||
else if rel='members' then
|
else if rel='members' then
|
||||||
call symputx('mref',quote(cats(href,'?recursive=true')),'l');
|
call symputx('mref',quote(cats("&base_uri",href,'?recursive=true')),'l');
|
||||||
run;
|
run;
|
||||||
|
|
||||||
/* before we can delete the folder, we need to delete the children */
|
/* before we can delete the folder, we need to delete the children */
|
||||||
@@ -10867,7 +10942,7 @@ data _null_;
|
|||||||
set &libref1a..items_links;
|
set &libref1a..items_links;
|
||||||
if href=:'/folders/folders' then return;
|
if href=:'/folders/folders' then return;
|
||||||
if rel='deleteResource' then
|
if rel='deleteResource' then
|
||||||
call execute('proc http method="DELETE" url='!!quote(trim(href))
|
call execute('proc http method="DELETE" url='!!quote("&base_uri"!!trim(href))
|
||||||
!!'; headers "Authorization"="Bearer &&&access_token_var" '
|
!!'; headers "Authorization"="Bearer &&&access_token_var" '
|
||||||
!!' "Accept"="*/*";run; /**/');
|
!!' "Accept"="*/*";run; /**/');
|
||||||
run;
|
run;
|
||||||
@@ -10952,8 +11027,8 @@ libname &libref1 clear;
|
|||||||
)
|
)
|
||||||
|
|
||||||
%mend;/**
|
%mend;/**
|
||||||
@file mv_getgroups.sas
|
@file mv_getclients.sas
|
||||||
@brief Creates a dataset with a list of viya groups
|
@brief Get a list of Viya Clients
|
||||||
@details First, be sure you have an access token (which requires an app token).
|
@details First, be sure you have an access token (which requires an app token).
|
||||||
|
|
||||||
Using the macros here:
|
Using the macros here:
|
||||||
@@ -10973,7 +11048,7 @@ libname &libref1 clear;
|
|||||||
|
|
||||||
Now we can run the macro!
|
Now we can run the macro!
|
||||||
|
|
||||||
%mv_getgroups()
|
%mv_getclients()
|
||||||
|
|
||||||
@param access_token_var= The global macro variable to contain the access token
|
@param access_token_var= The global macro variable to contain the access token
|
||||||
@param grant_type= valid values are "password" or "authorization_code" (unquoted).
|
@param grant_type= valid values are "password" or "authorization_code" (unquoted).
|
||||||
@@ -11118,7 +11193,7 @@ options noquotelenmax;
|
|||||||
%if "&root"="/" %then %do;
|
%if "&root"="/" %then %do;
|
||||||
/* if root just list root folders */
|
/* if root just list root folders */
|
||||||
proc http method='GET' out=&fname1 &oauth_bearer
|
proc http method='GET' out=&fname1 &oauth_bearer
|
||||||
url='%sysfunc(getoption(servicesbaseurl))/folders/rootFolders';
|
url="&base_uri/folders/rootFolders";
|
||||||
%if &grant_type=authorization_code %then %do;
|
%if &grant_type=authorization_code %then %do;
|
||||||
headers "Authorization"="Bearer &&&access_token_var";
|
headers "Authorization"="Bearer &&&access_token_var";
|
||||||
%end;
|
%end;
|
||||||
@@ -11141,7 +11216,7 @@ options noquotelenmax;
|
|||||||
/* now get the followon link to list members */
|
/* now get the followon link to list members */
|
||||||
data _null_;
|
data _null_;
|
||||||
set &libref1..links;
|
set &libref1..links;
|
||||||
if rel='members' then call symputx('href',quote(trim(href)),'l');
|
if rel='members' then call symputx('href',quote("&base_uri"!!trim(href)),'l');
|
||||||
run;
|
run;
|
||||||
%local fname2 libref2;
|
%local fname2 libref2;
|
||||||
%let fname2=%mf_getuniquefileref();
|
%let fname2=%mf_getuniquefileref();
|
||||||
@@ -11404,24 +11479,15 @@ libname &libref1 clear;
|
|||||||
%mend;/**
|
%mend;/**
|
||||||
@file mv_getusergroups.sas
|
@file mv_getusergroups.sas
|
||||||
@brief Creates a dataset with a list of groups for a particular user
|
@brief Creates a dataset with a list of groups for a particular user
|
||||||
@details First, be sure you have an access token (which requires an app token).
|
@details If using outside of Viya SPRE, then an access token is needed.
|
||||||
|
|
||||||
Using the macros here:
|
Compile the macros here:
|
||||||
|
|
||||||
filename mc url
|
filename mc url
|
||||||
"https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
"https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
||||||
%inc mc;
|
%inc mc;
|
||||||
|
|
||||||
An administrator needs to set you up with an access code:
|
Then run the macro!
|
||||||
|
|
||||||
%mv_registerclient(outds=client)
|
|
||||||
|
|
||||||
Navigate to the url from the log (opting in to the groups) and paste the
|
|
||||||
access code below:
|
|
||||||
|
|
||||||
%mv_tokenauth(inds=client,code=wKDZYTEPK6)
|
|
||||||
|
|
||||||
Now we can run the macro!
|
|
||||||
|
|
||||||
%mv_getusergroups(&sysuserid,outds=users)
|
%mv_getusergroups(&sysuserid,outds=users)
|
||||||
|
|
||||||
@@ -11458,7 +11524,7 @@ libname &libref1 clear;
|
|||||||
%let &access_token_var=;
|
%let &access_token_var=;
|
||||||
%end;
|
%end;
|
||||||
%put &sysmacroname: grant_type=&grant_type;
|
%put &sysmacroname: grant_type=&grant_type;
|
||||||
%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
|
%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
|
||||||
and &grant_type ne sas_services
|
and &grant_type ne sas_services
|
||||||
)
|
)
|
||||||
,mac=&sysmacroname
|
,mac=&sysmacroname
|
||||||
@@ -11476,7 +11542,7 @@ options noquotelenmax;
|
|||||||
|
|
||||||
proc http method='GET' out=&fname1 &oauth_bearer
|
proc http method='GET' out=&fname1 &oauth_bearer
|
||||||
url="&base_uri/identities/users/&user/memberships?limit=10000";
|
url="&base_uri/identities/users/&user/memberships?limit=10000";
|
||||||
headers
|
headers
|
||||||
%if &grant_type=authorization_code %then %do;
|
%if &grant_type=authorization_code %then %do;
|
||||||
"Authorization"="Bearer &&&access_token_var"
|
"Authorization"="Bearer &&&access_token_var"
|
||||||
%end;
|
%end;
|
||||||
@@ -11807,7 +11873,7 @@ run;
|
|||||||
%end;
|
%end;
|
||||||
|
|
||||||
/* prepare url */
|
/* prepare url */
|
||||||
%if &grant_type=authorization_code %then %do;
|
%if %index(%superq(grant_type),authorization_code) %then %do;
|
||||||
data _null_;
|
data _null_;
|
||||||
if symexist('_baseurl') then do;
|
if symexist('_baseurl') then do;
|
||||||
url=symget('_baseurl');
|
url=symget('_baseurl');
|
||||||
@@ -11826,7 +11892,7 @@ run;
|
|||||||
%put CLIENT_SECRET=&client_secret;
|
%put CLIENT_SECRET=&client_secret;
|
||||||
%put GRANT_TYPE=&grant_type;
|
%put GRANT_TYPE=&grant_type;
|
||||||
%put;
|
%put;
|
||||||
%if &grant_type=authorization_code %then %do;
|
%if %index(%superq(grant_type),authorization_code) %then %do;
|
||||||
/* cannot use base_uri here as it includes the protocol which may be incorrect externally */
|
/* cannot use base_uri here as it includes the protocol which may be incorrect externally */
|
||||||
%put NOTE: The developer must also register below and select 'openid' to get the grant code:;
|
%put NOTE: The developer must also register below and select 'openid' to get the grant code:;
|
||||||
%put NOTE- ;
|
%put NOTE- ;
|
||||||
@@ -11893,6 +11959,7 @@ libname &libref clear;
|
|||||||
@param pass= If grant_type=password then provide the password here
|
@param pass= If grant_type=password then provide the password here
|
||||||
@param access_token_var= The global macro variable to contain the access token
|
@param access_token_var= The global macro variable to contain the access token
|
||||||
@param refresh_token_var= The global macro variable to contain the refresh token
|
@param refresh_token_var= The global macro variable to contain the refresh token
|
||||||
|
@param base_uri= The Viya API server location
|
||||||
|
|
||||||
@version VIYA V.03.04
|
@version VIYA V.03.04
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
@@ -11917,6 +11984,7 @@ libname &libref clear;
|
|||||||
,pass=
|
,pass=
|
||||||
,access_token_var=ACCESS_TOKEN
|
,access_token_var=ACCESS_TOKEN
|
||||||
,refresh_token_var=REFRESH_TOKEN
|
,refresh_token_var=REFRESH_TOKEN
|
||||||
|
,base_uri=#NOTSET#
|
||||||
);
|
);
|
||||||
%global &access_token_var &refresh_token_var;
|
%global &access_token_var &refresh_token_var;
|
||||||
|
|
||||||
@@ -11963,8 +12031,7 @@ run;
|
|||||||
/**
|
/**
|
||||||
* Request access token
|
* Request access token
|
||||||
*/
|
*/
|
||||||
%local base_uri; /* location of rest apis */
|
%if &base_uri=#NOTSET# %then %let base_uri=%mf_getplatform(VIYARESTAPI);
|
||||||
%let base_uri=%mf_getplatform(VIYARESTAPI);
|
|
||||||
|
|
||||||
%let fref2=%mf_getuniquefileref();
|
%let fref2=%mf_getuniquefileref();
|
||||||
proc http method='POST' in=&grantstring out=&fref2
|
proc http method='POST' in=&grantstring out=&fref2
|
||||||
|
|||||||
@@ -12,6 +12,7 @@
|
|||||||
|
|
||||||
<h4> Dependencies </h4>
|
<h4> Dependencies </h4>
|
||||||
@li mf_mval.sas
|
@li mf_mval.sas
|
||||||
|
@li mf_trimstr.sas
|
||||||
|
|
||||||
@version 9.4 / 3.4
|
@version 9.4 / 3.4
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
@@ -57,6 +58,6 @@
|
|||||||
%else 0;
|
%else 0;
|
||||||
%end;
|
%end;
|
||||||
%else %if &switch=VIYARESTAPI %then %do;
|
%else %if &switch=VIYARESTAPI %then %do;
|
||||||
%sysfunc(getoption(servicesbaseurl))
|
%mf_trimstr(%sysfunc(getoption(servicesbaseurl)),/)
|
||||||
%end;
|
%end;
|
||||||
%mend;
|
%mend;
|
||||||
49
base/mf_trimstr.sas
Normal file
49
base/mf_trimstr.sas
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/**
|
||||||
|
@file mf_trimstr.sas
|
||||||
|
@brief Removes character(s) from the end, if they exist
|
||||||
|
@details If the designated characters exist at the end of the string, they
|
||||||
|
are removed
|
||||||
|
|
||||||
|
%put %mf_trimstr(/blah/,/); * /blah;
|
||||||
|
%put %mf_trimstr(/blah/,h); * /blah/;
|
||||||
|
%put %mf_trimstr(/blah/,h/);* /bla;
|
||||||
|
|
||||||
|
<h4> Dependencies </h4>
|
||||||
|
|
||||||
|
|
||||||
|
@param basestr The string to be modified
|
||||||
|
@param trimstr The string to be removed from the end of `basestr`, if it exists
|
||||||
|
|
||||||
|
@return output returns result with the value of `trimstr` removed from the end
|
||||||
|
|
||||||
|
|
||||||
|
@version 9.2
|
||||||
|
@author Allan Bowe
|
||||||
|
|
||||||
|
**/
|
||||||
|
|
||||||
|
%macro mf_trimstr(basestr,trimstr);
|
||||||
|
%local baselen trimlen trimval;
|
||||||
|
|
||||||
|
/* return if basestr is shorter than trimstr (or 0) */
|
||||||
|
%let baselen=%length(%superq(basestr));
|
||||||
|
%let trimlen=%length(%superq(trimstr));
|
||||||
|
%if &baselen < &trimlen or &baselen=0 %then %return;
|
||||||
|
|
||||||
|
/* obtain the characters from the end of basestr */
|
||||||
|
%let trimval=%qsubstr(%superq(basestr)
|
||||||
|
,%length(%superq(basestr))-&trimlen+1
|
||||||
|
,&trimlen);
|
||||||
|
|
||||||
|
/* compare and if matching, chop it off! */
|
||||||
|
%if %superq(basestr)=%superq(trimstr) %then %do;
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
|
%else %if %superq(trimval)=%superq(trimstr) %then %do;
|
||||||
|
%qsubstr(%superq(basestr),1,%length(%superq(basestr))-&trimlen)
|
||||||
|
%end;
|
||||||
|
%else %do;
|
||||||
|
&basestr
|
||||||
|
%end;
|
||||||
|
|
||||||
|
%mend;
|
||||||
@@ -5,6 +5,12 @@
|
|||||||
the particulars of an environment. For instance, can stream custom
|
the particulars of an environment. For instance, can stream custom
|
||||||
results back to the client in an STP Web App context, or completely stop
|
results back to the client in an STP Web App context, or completely stop
|
||||||
in the case of a batch run.
|
in the case of a batch run.
|
||||||
|
|
||||||
|
Using SAS Abort Cancel mechanisms can cause hung sessions in some Stored Process
|
||||||
|
environments. This macro takes a unique approach - we set the SAS syscc to 0,
|
||||||
|
run `stpsrvset('program error', 0)` (if SAS 9) and then - we open a macro
|
||||||
|
but don't close it! This provides a graceful abort for SAS web services in all
|
||||||
|
web enabled environments.
|
||||||
|
|
||||||
@param mac= to contain the name of the calling macro
|
@param mac= to contain the name of the calling macro
|
||||||
@param msg= message to be returned
|
@param msg= message to be returned
|
||||||
@@ -65,8 +71,15 @@
|
|||||||
%end;
|
%end;
|
||||||
|
|
||||||
%if %symexist(SYS_JES_JOB_URI) %then %do;
|
%if %symexist(SYS_JES_JOB_URI) %then %do;
|
||||||
/* refer web service output to file service in one hit */
|
/* setup webout */
|
||||||
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI" name="_webout.json";
|
OPTIONS NOBOMFILE;
|
||||||
|
%if "X&SYS_JES_JOB_URI.X"="XX" %then %do;
|
||||||
|
filename _webout temp lrecl=999999 mod;
|
||||||
|
%end;
|
||||||
|
%else %do;
|
||||||
|
filename _webout filesrvc parenturi="&SYS_JES_JOB_URI"
|
||||||
|
name="_webout.json" lrecl=999999 mod;
|
||||||
|
%end;
|
||||||
%end;
|
%end;
|
||||||
|
|
||||||
/* send response in SASjs JSON format */
|
/* send response in SASjs JSON format */
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
@brief Searches all data in a library
|
@brief Searches all data in a library
|
||||||
@details
|
@details
|
||||||
Scans an entire library and creates a copy of any table
|
Scans an entire library and creates a copy of any table
|
||||||
containing a specific string or numeric value. Only
|
containing a specific string OR numeric value. Only
|
||||||
matching records are written out.
|
matching records are written out.
|
||||||
If both a string and numval are provided, the string
|
If both a string and numval are provided, the string
|
||||||
will take precedence.
|
will take precedence.
|
||||||
@@ -44,9 +44,13 @@
|
|||||||
,filter_text=%str(1=1)
|
,filter_text=%str(1=1)
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
|
|
||||||
%local table_list table table_num table colnum col start_tm vars type coltype;
|
%local table_list table table_num table colnum col start_tm check_tm vars type coltype;
|
||||||
%put process began at %sysfunc(datetime(),datetime19.);
|
%put process began at %sysfunc(datetime(),datetime19.);
|
||||||
|
|
||||||
|
%if &syscc ge 4 %then %do;
|
||||||
|
%put %str(WAR)NING: SYSCC=&syscc on macro entry;
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
|
|
||||||
%if &string = %then %let type=N;
|
%if &string = %then %let type=N;
|
||||||
%else %let type=C;
|
%else %let type=C;
|
||||||
@@ -78,6 +82,7 @@ proc sql
|
|||||||
%put NO COLUMNS IN &lib..&table! This will be skipped.;
|
%put NO COLUMNS IN &lib..&table! This will be skipped.;
|
||||||
%end;
|
%end;
|
||||||
%else %do;
|
%else %do;
|
||||||
|
%let check_tm=%sysfunc(datetime());
|
||||||
/* build sql statement */
|
/* build sql statement */
|
||||||
create table mpsearch.&table as select * from &lib..&table
|
create table mpsearch.&table as select * from &lib..&table
|
||||||
where %unquote(&filter_text) and
|
where %unquote(&filter_text) and
|
||||||
@@ -88,14 +93,19 @@ proc sql
|
|||||||
%let coltype=%mf_getvartype(&lib..&table,&col);
|
%let coltype=%mf_getvartype(&lib..&table,&col);
|
||||||
%if &type=C and &coltype=C %then %do;
|
%if &type=C and &coltype=C %then %do;
|
||||||
/* if a char column, see if it contains the string */
|
/* if a char column, see if it contains the string */
|
||||||
or (&col ? "&string")
|
or ("&col"n ? "&string")
|
||||||
%end;
|
%end;
|
||||||
%else %if &type=N and &coltype=N %then %do;
|
%else %if &type=N and &coltype=N %then %do;
|
||||||
/* if numeric match exactly */
|
/* if numeric match exactly */
|
||||||
or (&col = &numval)
|
or ("&col"n = &numval)
|
||||||
%end;
|
%end;
|
||||||
%end;
|
%end;
|
||||||
);
|
);
|
||||||
|
%put Search query for &table took %sysevalf(%sysfunc(datetime())-&check_tm) seconds;
|
||||||
|
%if &sqlrc ne 0 %then %do;
|
||||||
|
%put %str(WAR)NING: SQLRC=&sqlrc when processing &table;
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
%if %mf_nobs(mpsearch.&table)=0 %then %do;
|
%if %mf_nobs(mpsearch.&table)=0 %then %do;
|
||||||
drop table mpsearch.&table;
|
drop table mpsearch.&table;
|
||||||
%end;
|
%end;
|
||||||
|
|||||||
@@ -16,7 +16,7 @@
|
|||||||
<tab type="classmembers" visible="no" title="" intro=""/>
|
<tab type="classmembers" visible="no" title="" intro=""/>
|
||||||
</tab>
|
</tab>
|
||||||
|
|
||||||
<tab type="filelist" visible="yes" title="" intro="List of Files Used in the Macro Core Library"/>
|
<tab type="filelist" visible="yes" title="" intro="List of Files Used in the Macro-Core Library"/>
|
||||||
|
|
||||||
<tab type="examples" visible="yes" title="" intro=""/>
|
<tab type="examples" visible="yes" title="" intro=""/>
|
||||||
</navindex>
|
</navindex>
|
||||||
|
|||||||
@@ -124,6 +124,7 @@ data _null_;
|
|||||||
when ('
') rec='0A'x;
|
when ('
') rec='0A'x;
|
||||||
when ('
') rec='0D'x;
|
when ('
') rec='0D'x;
|
||||||
when ('$' ) rec='$' ;
|
when ('$' ) rec='$' ;
|
||||||
|
when ('	') rec='09'x;
|
||||||
otherwise putlog "WARNING: missing value for " entity=;
|
otherwise putlog "WARNING: missing value for " entity=;
|
||||||
end;
|
end;
|
||||||
rc =fput(fileid, substr(rec,1,1));
|
rc =fput(fileid, substr(rec,1,1));
|
||||||
|
|||||||
@@ -123,6 +123,7 @@ data _null_;
|
|||||||
when ('
') rec='0A'x;
|
when ('
') rec='0A'x;
|
||||||
when ('
') rec='0D'x;
|
when ('
') rec='0D'x;
|
||||||
when ('$' ) rec='$' ;
|
when ('$' ) rec='$' ;
|
||||||
|
when ('	') rec='09'x;
|
||||||
otherwise putlog "%str(WARN)ING: missing value for " entity=;
|
otherwise putlog "%str(WARN)ING: missing value for " entity=;
|
||||||
end;
|
end;
|
||||||
rc =fput(fileid, substr(rec,1,1));
|
rc =fput(fileid, substr(rec,1,1));
|
||||||
|
|||||||
@@ -99,6 +99,7 @@ run;
|
|||||||
when ('
') rec='0A'x;
|
when ('
') rec='0A'x;
|
||||||
when ('
') rec='0D'x;
|
when ('
') rec='0D'x;
|
||||||
when ('$' ) rec='$' ;
|
when ('$' ) rec='$' ;
|
||||||
|
when ('	') rec='09'x;
|
||||||
otherwise putlog "WARNING: missing value for " entity=;
|
otherwise putlog "WARNING: missing value for " entity=;
|
||||||
end;
|
end;
|
||||||
rc =fput(fileid, substr(rec,1,1));
|
rc =fput(fileid, substr(rec,1,1));
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ run;
|
|||||||
libname &libref1 JSON fileref=&fname1;
|
libname &libref1 JSON fileref=&fname1;
|
||||||
data _null_;
|
data _null_;
|
||||||
set &libref1..links;
|
set &libref1..links;
|
||||||
if rel='members' then call symputx('mref',quote(trim(href)),'l');
|
if rel='members' then call symputx('mref',quote("&base_uri"!!trim(href)),'l');
|
||||||
run;
|
run;
|
||||||
|
|
||||||
/* get the children */
|
/* get the children */
|
||||||
@@ -128,7 +128,7 @@ run;
|
|||||||
%put NOTE:;%put NOTE- &sysmacroname: &path/&name NOT FOUND;%put NOTE- ;
|
%put NOTE:;%put NOTE- &sysmacroname: &path/&name NOT FOUND;%put NOTE- ;
|
||||||
%return;
|
%return;
|
||||||
%end;
|
%end;
|
||||||
proc http method="DELETE" url="&uri" &oauth_bearer;
|
proc http method="DELETE" url="&base_uri&uri" &oauth_bearer;
|
||||||
headers
|
headers
|
||||||
%if &grant_type=authorization_code %then %do;
|
%if &grant_type=authorization_code %then %do;
|
||||||
"Authorization"="Bearer &&&access_token_var"
|
"Authorization"="Bearer &&&access_token_var"
|
||||||
|
|||||||
@@ -88,9 +88,9 @@ libname &libref1 JSON fileref=&fname1;
|
|||||||
data _null_;
|
data _null_;
|
||||||
set &libref1..links;
|
set &libref1..links;
|
||||||
if rel='deleteRecursively' then
|
if rel='deleteRecursively' then
|
||||||
call symputx('href',quote(trim(href)),'l');
|
call symputx('href',quote("&base_uri"!!trim(href)),'l');
|
||||||
else if rel='members' then
|
else if rel='members' then
|
||||||
call symputx('mref',quote(cats(href,'?recursive=true')),'l');
|
call symputx('mref',quote(cats("&base_uri",href,'?recursive=true')),'l');
|
||||||
run;
|
run;
|
||||||
|
|
||||||
/* before we can delete the folder, we need to delete the children */
|
/* before we can delete the folder, we need to delete the children */
|
||||||
@@ -111,7 +111,7 @@ data _null_;
|
|||||||
set &libref1a..items_links;
|
set &libref1a..items_links;
|
||||||
if href=:'/folders/folders' then return;
|
if href=:'/folders/folders' then return;
|
||||||
if rel='deleteResource' then
|
if rel='deleteResource' then
|
||||||
call execute('proc http method="DELETE" url='!!quote(trim(href))
|
call execute('proc http method="DELETE" url='!!quote("&base_uri"!!trim(href))
|
||||||
!!'; headers "Authorization"="Bearer &&&access_token_var" '
|
!!'; headers "Authorization"="Bearer &&&access_token_var" '
|
||||||
!!' "Accept"="*/*";run; /**/');
|
!!' "Accept"="*/*";run; /**/');
|
||||||
run;
|
run;
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/**
|
/**
|
||||||
@file mv_getgroups.sas
|
@file mv_getclients.sas
|
||||||
@brief Creates a dataset with a list of viya groups
|
@brief Get a list of Viya Clients
|
||||||
@details First, be sure you have an access token (which requires an app token).
|
@details First, be sure you have an access token (which requires an app token).
|
||||||
|
|
||||||
Using the macros here:
|
Using the macros here:
|
||||||
@@ -20,7 +20,7 @@
|
|||||||
|
|
||||||
Now we can run the macro!
|
Now we can run the macro!
|
||||||
|
|
||||||
%mv_getgroups()
|
%mv_getclients()
|
||||||
|
|
||||||
@param access_token_var= The global macro variable to contain the access token
|
@param access_token_var= The global macro variable to contain the access token
|
||||||
@param grant_type= valid values are "password" or "authorization_code" (unquoted).
|
@param grant_type= valid values are "password" or "authorization_code" (unquoted).
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ options noquotelenmax;
|
|||||||
%if "&root"="/" %then %do;
|
%if "&root"="/" %then %do;
|
||||||
/* if root just list root folders */
|
/* if root just list root folders */
|
||||||
proc http method='GET' out=&fname1 &oauth_bearer
|
proc http method='GET' out=&fname1 &oauth_bearer
|
||||||
url='%sysfunc(getoption(servicesbaseurl))/folders/rootFolders';
|
url="&base_uri/folders/rootFolders";
|
||||||
%if &grant_type=authorization_code %then %do;
|
%if &grant_type=authorization_code %then %do;
|
||||||
headers "Authorization"="Bearer &&&access_token_var";
|
headers "Authorization"="Bearer &&&access_token_var";
|
||||||
%end;
|
%end;
|
||||||
@@ -87,7 +87,7 @@ options noquotelenmax;
|
|||||||
/* now get the followon link to list members */
|
/* now get the followon link to list members */
|
||||||
data _null_;
|
data _null_;
|
||||||
set &libref1..links;
|
set &libref1..links;
|
||||||
if rel='members' then call symputx('href',quote(trim(href)),'l');
|
if rel='members' then call symputx('href',quote("&base_uri"!!trim(href)),'l');
|
||||||
run;
|
run;
|
||||||
%local fname2 libref2;
|
%local fname2 libref2;
|
||||||
%let fname2=%mf_getuniquefileref();
|
%let fname2=%mf_getuniquefileref();
|
||||||
|
|||||||
@@ -1,24 +1,15 @@
|
|||||||
/**
|
/**
|
||||||
@file mv_getusergroups.sas
|
@file mv_getusergroups.sas
|
||||||
@brief Creates a dataset with a list of groups for a particular user
|
@brief Creates a dataset with a list of groups for a particular user
|
||||||
@details First, be sure you have an access token (which requires an app token).
|
@details If using outside of Viya SPRE, then an access token is needed.
|
||||||
|
|
||||||
Using the macros here:
|
Compile the macros here:
|
||||||
|
|
||||||
filename mc url
|
filename mc url
|
||||||
"https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
"https://raw.githubusercontent.com/sasjs/core/main/all.sas";
|
||||||
%inc mc;
|
%inc mc;
|
||||||
|
|
||||||
An administrator needs to set you up with an access code:
|
Then run the macro!
|
||||||
|
|
||||||
%mv_registerclient(outds=client)
|
|
||||||
|
|
||||||
Navigate to the url from the log (opting in to the groups) and paste the
|
|
||||||
access code below:
|
|
||||||
|
|
||||||
%mv_tokenauth(inds=client,code=wKDZYTEPK6)
|
|
||||||
|
|
||||||
Now we can run the macro!
|
|
||||||
|
|
||||||
%mv_getusergroups(&sysuserid,outds=users)
|
%mv_getusergroups(&sysuserid,outds=users)
|
||||||
|
|
||||||
@@ -55,7 +46,7 @@
|
|||||||
%let &access_token_var=;
|
%let &access_token_var=;
|
||||||
%end;
|
%end;
|
||||||
%put &sysmacroname: grant_type=&grant_type;
|
%put &sysmacroname: grant_type=&grant_type;
|
||||||
%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
|
%mp_abort(iftrue=(&grant_type ne authorization_code and &grant_type ne password
|
||||||
and &grant_type ne sas_services
|
and &grant_type ne sas_services
|
||||||
)
|
)
|
||||||
,mac=&sysmacroname
|
,mac=&sysmacroname
|
||||||
@@ -73,7 +64,7 @@ options noquotelenmax;
|
|||||||
|
|
||||||
proc http method='GET' out=&fname1 &oauth_bearer
|
proc http method='GET' out=&fname1 &oauth_bearer
|
||||||
url="&base_uri/identities/users/&user/memberships?limit=10000";
|
url="&base_uri/identities/users/&user/memberships?limit=10000";
|
||||||
headers
|
headers
|
||||||
%if &grant_type=authorization_code %then %do;
|
%if &grant_type=authorization_code %then %do;
|
||||||
"Authorization"="Bearer &&&access_token_var"
|
"Authorization"="Bearer &&&access_token_var"
|
||||||
%end;
|
%end;
|
||||||
|
|||||||
@@ -187,7 +187,7 @@ run;
|
|||||||
%end;
|
%end;
|
||||||
|
|
||||||
/* prepare url */
|
/* prepare url */
|
||||||
%if &grant_type=authorization_code %then %do;
|
%if %index(%superq(grant_type),authorization_code) %then %do;
|
||||||
data _null_;
|
data _null_;
|
||||||
if symexist('_baseurl') then do;
|
if symexist('_baseurl') then do;
|
||||||
url=symget('_baseurl');
|
url=symget('_baseurl');
|
||||||
@@ -206,7 +206,7 @@ run;
|
|||||||
%put CLIENT_SECRET=&client_secret;
|
%put CLIENT_SECRET=&client_secret;
|
||||||
%put GRANT_TYPE=&grant_type;
|
%put GRANT_TYPE=&grant_type;
|
||||||
%put;
|
%put;
|
||||||
%if &grant_type=authorization_code %then %do;
|
%if %index(%superq(grant_type),authorization_code) %then %do;
|
||||||
/* cannot use base_uri here as it includes the protocol which may be incorrect externally */
|
/* cannot use base_uri here as it includes the protocol which may be incorrect externally */
|
||||||
%put NOTE: The developer must also register below and select 'openid' to get the grant code:;
|
%put NOTE: The developer must also register below and select 'openid' to get the grant code:;
|
||||||
%put NOTE- ;
|
%put NOTE- ;
|
||||||
|
|||||||
@@ -38,6 +38,7 @@
|
|||||||
@param pass= If grant_type=password then provide the password here
|
@param pass= If grant_type=password then provide the password here
|
||||||
@param access_token_var= The global macro variable to contain the access token
|
@param access_token_var= The global macro variable to contain the access token
|
||||||
@param refresh_token_var= The global macro variable to contain the refresh token
|
@param refresh_token_var= The global macro variable to contain the refresh token
|
||||||
|
@param base_uri= The Viya API server location
|
||||||
|
|
||||||
@version VIYA V.03.04
|
@version VIYA V.03.04
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
@@ -62,6 +63,7 @@
|
|||||||
,pass=
|
,pass=
|
||||||
,access_token_var=ACCESS_TOKEN
|
,access_token_var=ACCESS_TOKEN
|
||||||
,refresh_token_var=REFRESH_TOKEN
|
,refresh_token_var=REFRESH_TOKEN
|
||||||
|
,base_uri=#NOTSET#
|
||||||
);
|
);
|
||||||
%global &access_token_var &refresh_token_var;
|
%global &access_token_var &refresh_token_var;
|
||||||
|
|
||||||
@@ -108,8 +110,7 @@ run;
|
|||||||
/**
|
/**
|
||||||
* Request access token
|
* Request access token
|
||||||
*/
|
*/
|
||||||
%local base_uri; /* location of rest apis */
|
%if &base_uri=#NOTSET# %then %let base_uri=%mf_getplatform(VIYARESTAPI);
|
||||||
%let base_uri=%mf_getplatform(VIYARESTAPI);
|
|
||||||
|
|
||||||
%let fref2=%mf_getuniquefileref();
|
%let fref2=%mf_getuniquefileref();
|
||||||
proc http method='POST' in=&grantstring out=&fref2
|
proc http method='POST' in=&grantstring out=&fref2
|
||||||
|
|||||||
Reference in New Issue
Block a user