mirror of
https://github.com/sasjs/core.git
synced 2026-01-03 23:50:06 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ada9192337 | ||
|
|
6161f588a9 | ||
|
|
67079d8c17 |
73
all.sas
73
all.sas
@@ -160,21 +160,23 @@ options noquotelenmax;
|
|||||||
Full credit to [Bart](https://sasensei.com/user/305) for the vfunc pointer
|
Full credit to [Bart](https://sasensei.com/user/305) for the vfunc pointer
|
||||||
and the tidy approach for pure macro data set filtering.
|
and the tidy approach for pure macro data set filtering.
|
||||||
Check out his [SAS Packages](https://github.com/yabwon/SAS_PACKAGES)
|
Check out his [SAS Packages](https://github.com/yabwon/SAS_PACKAGES)
|
||||||
framework!
|
framework! Where you can find the same [function](
|
||||||
|
https://github.com/yabwon/SAS_PACKAGES/blob/main/packages/baseplus.md#functionexists-macro
|
||||||
|
).
|
||||||
|
|
||||||
@param [in] name (positional) - function name
|
@param [in] name (positional) - function name
|
||||||
|
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
**/
|
**/
|
||||||
/** @cond */
|
/** @cond */
|
||||||
|
|
||||||
%macro mf_existfunction(name
|
%macro mf_existfunction(name
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
|
|
||||||
%local dsid rc exist;
|
%local dsid rc exist;
|
||||||
%let dsid=%sysfunc(open(sashelp.vfunc(where=(fncname="%upcase(&name)"))));
|
%let dsid=%sysfunc(open(sashelp.vfunc(where=(fncname="%upcase(&name)"))));
|
||||||
%let exist = %sysfunc(fetch(&dsid, NOSET));
|
%let exist=1;
|
||||||
%let rc = %sysfunc(close(&dsid));
|
%let exist=%sysfunc(fetch(&dsid, NOSET));
|
||||||
|
%let rc=%sysfunc(close(&dsid));
|
||||||
|
|
||||||
%sysevalf(0 = &exist)
|
%sysevalf(0 = &exist)
|
||||||
|
|
||||||
@@ -310,13 +312,25 @@ options noquotelenmax;
|
|||||||
|
|
||||||
%macro mf_getapploc(pgm);
|
%macro mf_getapploc(pgm);
|
||||||
%if "&pgm"="" %then %do;
|
%if "&pgm"="" %then %do;
|
||||||
%put &sysmacroname: No value provided;
|
%if %symexist(_program) %then %let pgm=&_program;
|
||||||
%return;
|
%else %do;
|
||||||
|
%put &sysmacroname: No value provided and no _program variable available;
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
%end;
|
%end;
|
||||||
%local root;
|
%local root;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* move up two levels to avoid matches on subfolder or service name
|
* First check we are not in the tests/macros folder (which has no subfolders)
|
||||||
|
*/
|
||||||
|
%if %index(&pgm,/tests/macros/) %then %do;
|
||||||
|
%let root=%substr(&pgm,1,%index(&pgm,/tests/macros)-1);
|
||||||
|
&root
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Next, move up two levels to avoid matches on subfolder or service name
|
||||||
*/
|
*/
|
||||||
%let root=%substr(&pgm,1,%length(&pgm)-%length(%scan(&pgm,-1,/))-1);
|
%let root=%substr(&pgm,1,%length(&pgm)-%length(%scan(&pgm,-1,/))-1);
|
||||||
%let root=%substr(&root,1,%length(&root)-%length(%scan(&root,-1,/))-1);
|
%let root=%substr(&root,1,%length(&root)-%length(%scan(&root,-1,/))-1);
|
||||||
@@ -15380,24 +15394,27 @@ filename &fname1 clear;
|
|||||||
libname &libref1 clear;
|
libname &libref1 clear;
|
||||||
*/
|
*/
|
||||||
%mend mv_getclients;/**
|
%mend mv_getclients;/**
|
||||||
@file mv_getfoldermembers.sas
|
@file
|
||||||
@brief Gets a list of folders (and ids) for a given root
|
@brief Gets a list of folder members (and ids) for a given root
|
||||||
@details Works for both root level and below, oauth or password. Default is
|
@details Returns all members for a particular Viya folder. Works at both root
|
||||||
oauth, and the token is expected in a global ACCESS_TOKEN variable.
|
level and below, and results are created in an output dataset.
|
||||||
|
|
||||||
%mv_getfoldermembers(root=/Public)
|
%mv_getfoldermembers(root=/Public, outds=work.mymembers)
|
||||||
|
|
||||||
|
|
||||||
@param root= The path for which to return the list of folders
|
@param [in] root= (/) The path for which to return the list of folders
|
||||||
@param outds= The output dataset to create (default is work.mv_getfolders). Format:
|
@param [out] outds= (work.mv_getfolders) The output dataset to create. Format:
|
||||||
|ordinal_root|ordinal_items|creationTimeStamp| modifiedTimeStamp|createdBy|modifiedBy|id| uri|added| type|name|description|
|
|ordinal_root|ordinal_items|creationTimeStamp| modifiedTimeStamp|createdBy|modifiedBy|id| uri|added| type|name|description|
|
||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||
|1|1|2021-05-25T11:15:04.204Z|2021-05-25T11:15:04.204Z|allbow|allbow|4f1e3945-9655-462b-90f2-c31534b3ca47|/folders/folders/ed701ff3-77e8-468d-a4f5-8c43dec0fd9e|2021-05-25T11:15:04.212Z|child|my_folder_name|My folder Description|
|
|1|1|2021-05-25T11:15:04.204Z|2021-05-25T11:15:04.204Z|allbow|allbow|4f1e3945-9655-462b-90f2-c31534b3ca47|/folders/folders/ed701ff3-77e8-468d-a4f5-8c43dec0fd9e|2021-05-25T11:15:04.212Z|child|my_folder_name|My folder Description|
|
||||||
|
|
||||||
@param access_token_var= The global macro variable to contain the access token
|
@param [in] access_token_var= (ACCESS_TOKEN) The global macro variable to
|
||||||
@param grant_type= valid values are "password" or "authorization_code" (unquoted).
|
contain the access token
|
||||||
The default is authorization_code.
|
@param [in] grant_type= (sas_services) Valid values are:
|
||||||
|
@li password
|
||||||
|
@li authorization_code
|
||||||
|
@li detect
|
||||||
|
@li sas_services
|
||||||
|
|
||||||
@version VIYA V.03.04
|
@version VIYA V.03.04
|
||||||
@author Allan Bowe, source: https://github.com/sasjs/core
|
@author Allan Bowe, source: https://github.com/sasjs/core
|
||||||
@@ -15409,6 +15426,12 @@ libname &libref1 clear;
|
|||||||
@li mf_getuniquelibref.sas
|
@li mf_getuniquelibref.sas
|
||||||
@li mf_isblank.sas
|
@li mf_isblank.sas
|
||||||
|
|
||||||
|
<h4> Related Macros </h4>
|
||||||
|
@li mv_createfolder.sas
|
||||||
|
@li mv_deletefoldermember.sas
|
||||||
|
@li mv_deleteviyafolder.sas
|
||||||
|
@li mv_getfoldermembers.test.sas
|
||||||
|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
%macro mv_getfoldermembers(root=/
|
%macro mv_getfoldermembers(root=/
|
||||||
@@ -15448,7 +15471,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="&base_uri/folders/rootFolders";
|
url="&base_uri/folders/rootFolders?limit=1000";
|
||||||
%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;
|
||||||
@@ -15469,13 +15492,17 @@ options noquotelenmax;
|
|||||||
/*data _null_;infile &fname1;input;putlog _infile_;run;*/
|
/*data _null_;infile &fname1;input;putlog _infile_;run;*/
|
||||||
libname &libref1 JSON fileref=&fname1;
|
libname &libref1 JSON fileref=&fname1;
|
||||||
/* now get the followon link to list members */
|
/* now get the followon link to list members */
|
||||||
%local href;
|
%local href cnt;
|
||||||
%let href=0;
|
%let cnt=0;
|
||||||
data _null_;
|
data _null_;
|
||||||
set &libref1..links;
|
set &libref1..links;
|
||||||
if rel='members' then call symputx('href',quote("&base_uri"!!trim(href)),'l');
|
if rel='members' then do;
|
||||||
|
url=cats("'","&base_uri",href,"?limit=10000'");
|
||||||
|
call symputx('href',url,'l');
|
||||||
|
call symputx('cnt',1,'l');
|
||||||
|
end;
|
||||||
run;
|
run;
|
||||||
%if &href=0 %then %do;
|
%if &cnt=0 %then %do;
|
||||||
%put NOTE:;%put NOTE- No members found in &root!!;%put NOTE-;
|
%put NOTE:;%put NOTE- No members found in &root!!;%put NOTE-;
|
||||||
%return;
|
%return;
|
||||||
%end;
|
%end;
|
||||||
|
|||||||
@@ -12,21 +12,23 @@
|
|||||||
Full credit to [Bart](https://sasensei.com/user/305) for the vfunc pointer
|
Full credit to [Bart](https://sasensei.com/user/305) for the vfunc pointer
|
||||||
and the tidy approach for pure macro data set filtering.
|
and the tidy approach for pure macro data set filtering.
|
||||||
Check out his [SAS Packages](https://github.com/yabwon/SAS_PACKAGES)
|
Check out his [SAS Packages](https://github.com/yabwon/SAS_PACKAGES)
|
||||||
framework!
|
framework! Where you can find the same [function](
|
||||||
|
https://github.com/yabwon/SAS_PACKAGES/blob/main/packages/baseplus.md#functionexists-macro
|
||||||
|
).
|
||||||
|
|
||||||
@param [in] name (positional) - function name
|
@param [in] name (positional) - function name
|
||||||
|
|
||||||
@author Allan Bowe
|
@author Allan Bowe
|
||||||
**/
|
**/
|
||||||
/** @cond */
|
/** @cond */
|
||||||
|
|
||||||
%macro mf_existfunction(name
|
%macro mf_existfunction(name
|
||||||
)/*/STORE SOURCE*/;
|
)/*/STORE SOURCE*/;
|
||||||
|
|
||||||
%local dsid rc exist;
|
%local dsid rc exist;
|
||||||
%let dsid=%sysfunc(open(sashelp.vfunc(where=(fncname="%upcase(&name)"))));
|
%let dsid=%sysfunc(open(sashelp.vfunc(where=(fncname="%upcase(&name)"))));
|
||||||
%let exist = %sysfunc(fetch(&dsid, NOSET));
|
%let exist=1;
|
||||||
%let rc = %sysfunc(close(&dsid));
|
%let exist=%sysfunc(fetch(&dsid, NOSET));
|
||||||
|
%let rc=%sysfunc(close(&dsid));
|
||||||
|
|
||||||
%sysevalf(0 = &exist)
|
%sysevalf(0 = &exist)
|
||||||
|
|
||||||
|
|||||||
@@ -36,13 +36,25 @@
|
|||||||
|
|
||||||
%macro mf_getapploc(pgm);
|
%macro mf_getapploc(pgm);
|
||||||
%if "&pgm"="" %then %do;
|
%if "&pgm"="" %then %do;
|
||||||
%put &sysmacroname: No value provided;
|
%if %symexist(_program) %then %let pgm=&_program;
|
||||||
%return;
|
%else %do;
|
||||||
|
%put &sysmacroname: No value provided and no _program variable available;
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
%end;
|
%end;
|
||||||
%local root;
|
%local root;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* move up two levels to avoid matches on subfolder or service name
|
* First check we are not in the tests/macros folder (which has no subfolders)
|
||||||
|
*/
|
||||||
|
%if %index(&pgm,/tests/macros/) %then %do;
|
||||||
|
%let root=%substr(&pgm,1,%index(&pgm,/tests/macros)-1);
|
||||||
|
&root
|
||||||
|
%return;
|
||||||
|
%end;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Next, move up two levels to avoid matches on subfolder or service name
|
||||||
*/
|
*/
|
||||||
%let root=%substr(&pgm,1,%length(&pgm)-%length(%scan(&pgm,-1,/))-1);
|
%let root=%substr(&pgm,1,%length(&pgm)-%length(%scan(&pgm,-1,/))-1);
|
||||||
%let root=%substr(&root,1,%length(&root)-%length(%scan(&root,-1,/))-1);
|
%let root=%substr(&root,1,%length(&root)-%length(%scan(&root,-1,/))-1);
|
||||||
|
|||||||
@@ -38,4 +38,12 @@
|
|||||||
),
|
),
|
||||||
desc=Checking jobs appLoc matches,
|
desc=Checking jobs appLoc matches,
|
||||||
outds=work.test_results
|
outds=work.test_results
|
||||||
|
)
|
||||||
|
|
||||||
|
%mp_assert(
|
||||||
|
iftrue=(
|
||||||
|
"%mf_getapploc(/some/area/tests/macros/somemacro.sas)"="/some/area"
|
||||||
|
),
|
||||||
|
desc=Checking tests/macros appLoc matches (which has no subfolder),
|
||||||
|
outds=work.test_results
|
||||||
)
|
)
|
||||||
24
tests/viyaonly/mv_getfoldermembers.test.sas
Normal file
24
tests/viyaonly/mv_getfoldermembers.test.sas
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Testing mv_getfoldermembers macro
|
||||||
|
@details Testing is performed by ensuring that the tests/macros folder
|
||||||
|
contains more than 20 results (which also means the default was increased)
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mf_getapploc.sas
|
||||||
|
@li mp_assertdsobs.sas
|
||||||
|
@li mv_getfoldermembers.sas
|
||||||
|
|
||||||
|
**/
|
||||||
|
options mprint;
|
||||||
|
|
||||||
|
%mv_getfoldermembers(
|
||||||
|
root=%mf_getapploc()/tests/macros,
|
||||||
|
outds=work.results
|
||||||
|
)
|
||||||
|
|
||||||
|
%mp_assertdsobs(work.results,
|
||||||
|
desc=%str(Ensuring over 20 results found in %mf_getapploc()/tests/macros),
|
||||||
|
test=ATLEAST 21,
|
||||||
|
outds=work.test_results
|
||||||
|
)
|
||||||
@@ -1,22 +1,25 @@
|
|||||||
/**
|
/**
|
||||||
@file mv_getfoldermembers.sas
|
@file
|
||||||
@brief Gets a list of folders (and ids) for a given root
|
@brief Gets a list of folder members (and ids) for a given root
|
||||||
@details Works for both root level and below, oauth or password. Default is
|
@details Returns all members for a particular Viya folder. Works at both root
|
||||||
oauth, and the token is expected in a global ACCESS_TOKEN variable.
|
level and below, and results are created in an output dataset.
|
||||||
|
|
||||||
%mv_getfoldermembers(root=/Public)
|
%mv_getfoldermembers(root=/Public, outds=work.mymembers)
|
||||||
|
|
||||||
|
|
||||||
@param root= The path for which to return the list of folders
|
@param [in] root= (/) The path for which to return the list of folders
|
||||||
@param outds= The output dataset to create (default is work.mv_getfolders). Format:
|
@param [out] outds= (work.mv_getfolders) The output dataset to create. Format:
|
||||||
|ordinal_root|ordinal_items|creationTimeStamp| modifiedTimeStamp|createdBy|modifiedBy|id| uri|added| type|name|description|
|
|ordinal_root|ordinal_items|creationTimeStamp| modifiedTimeStamp|createdBy|modifiedBy|id| uri|added| type|name|description|
|
||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
|
|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||
|1|1|2021-05-25T11:15:04.204Z|2021-05-25T11:15:04.204Z|allbow|allbow|4f1e3945-9655-462b-90f2-c31534b3ca47|/folders/folders/ed701ff3-77e8-468d-a4f5-8c43dec0fd9e|2021-05-25T11:15:04.212Z|child|my_folder_name|My folder Description|
|
|1|1|2021-05-25T11:15:04.204Z|2021-05-25T11:15:04.204Z|allbow|allbow|4f1e3945-9655-462b-90f2-c31534b3ca47|/folders/folders/ed701ff3-77e8-468d-a4f5-8c43dec0fd9e|2021-05-25T11:15:04.212Z|child|my_folder_name|My folder Description|
|
||||||
|
|
||||||
@param access_token_var= The global macro variable to contain the access token
|
@param [in] access_token_var= (ACCESS_TOKEN) The global macro variable to
|
||||||
@param grant_type= valid values are "password" or "authorization_code" (unquoted).
|
contain the access token
|
||||||
The default is authorization_code.
|
@param [in] grant_type= (sas_services) Valid values are:
|
||||||
|
@li password
|
||||||
|
@li authorization_code
|
||||||
|
@li detect
|
||||||
|
@li sas_services
|
||||||
|
|
||||||
@version VIYA V.03.04
|
@version VIYA V.03.04
|
||||||
@author Allan Bowe, source: https://github.com/sasjs/core
|
@author Allan Bowe, source: https://github.com/sasjs/core
|
||||||
@@ -28,6 +31,12 @@
|
|||||||
@li mf_getuniquelibref.sas
|
@li mf_getuniquelibref.sas
|
||||||
@li mf_isblank.sas
|
@li mf_isblank.sas
|
||||||
|
|
||||||
|
<h4> Related Macros </h4>
|
||||||
|
@li mv_createfolder.sas
|
||||||
|
@li mv_deletefoldermember.sas
|
||||||
|
@li mv_deleteviyafolder.sas
|
||||||
|
@li mv_getfoldermembers.test.sas
|
||||||
|
|
||||||
**/
|
**/
|
||||||
|
|
||||||
%macro mv_getfoldermembers(root=/
|
%macro mv_getfoldermembers(root=/
|
||||||
@@ -67,7 +76,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="&base_uri/folders/rootFolders";
|
url="&base_uri/folders/rootFolders?limit=1000";
|
||||||
%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;
|
||||||
@@ -88,13 +97,17 @@ options noquotelenmax;
|
|||||||
/*data _null_;infile &fname1;input;putlog _infile_;run;*/
|
/*data _null_;infile &fname1;input;putlog _infile_;run;*/
|
||||||
libname &libref1 JSON fileref=&fname1;
|
libname &libref1 JSON fileref=&fname1;
|
||||||
/* now get the followon link to list members */
|
/* now get the followon link to list members */
|
||||||
%local href;
|
%local href cnt;
|
||||||
%let href=0;
|
%let cnt=0;
|
||||||
data _null_;
|
data _null_;
|
||||||
set &libref1..links;
|
set &libref1..links;
|
||||||
if rel='members' then call symputx('href',quote("&base_uri"!!trim(href)),'l');
|
if rel='members' then do;
|
||||||
|
url=cats("'","&base_uri",href,"?limit=10000'");
|
||||||
|
call symputx('href',url,'l');
|
||||||
|
call symputx('cnt',1,'l');
|
||||||
|
end;
|
||||||
run;
|
run;
|
||||||
%if &href=0 %then %do;
|
%if &cnt=0 %then %do;
|
||||||
%put NOTE:;%put NOTE- No members found in &root!!;%put NOTE-;
|
%put NOTE:;%put NOTE- No members found in &root!!;%put NOTE-;
|
||||||
%return;
|
%return;
|
||||||
%end;
|
%end;
|
||||||
|
|||||||
Reference in New Issue
Block a user