mirror of
https://github.com/sasjs/core.git
synced 2026-01-15 20:40:05 +00:00
feat: mm_getfoldercontents.sas to fetch immediate children for any folder including a root level folder
This commit is contained in:
111
all.sas
111
all.sas
@@ -8105,20 +8105,117 @@ filename __outdoc clear;
|
|||||||
|
|
||||||
%mend;
|
%mend;
|
||||||
/**
|
/**
|
||||||
@file mm_getfoldertree.sas
|
@file
|
||||||
|
@brief Returns all direct child members of a particular folder
|
||||||
|
@details Displays the children for a particular folder, in a similar fashion
|
||||||
|
to the viya counterpart (mv_getfoldermembers.sas)
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
%mm_getfoldermembers(root=/, outds=rootfolders)
|
||||||
|
|
||||||
|
%mm_getfoldermembers(root=/User Folders/&sysuserid, outds=usercontent)
|
||||||
|
|
||||||
|
@param [in] root= the parent folder under which to return all contents
|
||||||
|
@param [out] outds= the dataset to create that contains the list of directories
|
||||||
|
@param [in] mDebug= set to 1 to show debug messages in the log
|
||||||
|
|
||||||
|
<h4> Data Outputs </h4>
|
||||||
|
|
||||||
|
Example for `root=/`:
|
||||||
|
|
||||||
|
|metauri $17|metaname $256|metatype $32|
|
||||||
|
|---|---|---|
|
||||||
|
|A5XLSNXI.AA000001|Products |Folder|
|
||||||
|
|A5XLSNXI.AA000002|Shared Data |Folder|
|
||||||
|
|A5XLSNXI.AA000003|User Folders |Folder|
|
||||||
|
|A5XLSNXI.AA000004|System |Folder|
|
||||||
|
|A5XLSNXI.AA00003K|30.SASApps |Folder|
|
||||||
|
|A5XLSNXI.AA00006A|Public|Folder|
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mm_getfoldertree.sas
|
||||||
|
@li mf_getuniquefileref.sas
|
||||||
|
@li mf_getuniquelibref.sas
|
||||||
|
|
||||||
|
@version 9.4
|
||||||
|
@author Allan Bowe
|
||||||
|
|
||||||
|
**/
|
||||||
|
%macro mm_getfoldermembers(
|
||||||
|
root=
|
||||||
|
,outds=work.mm_getfoldertree
|
||||||
|
)/*/STORE SOURCE*/;
|
||||||
|
|
||||||
|
%if "&root" = "/" %then %do;
|
||||||
|
%local fname1 fname2 fname3;
|
||||||
|
%let fname1=%mf_getuniquefileref();
|
||||||
|
%let fname2=%mf_getuniquefileref();
|
||||||
|
%let fname3=%mf_getuniquefileref();
|
||||||
|
data _null_ ;
|
||||||
|
file &fname1 ;
|
||||||
|
put '<GetMetadataObjects>' ;
|
||||||
|
put '<Reposid>$METAREPOSITORY</Reposid>' ;
|
||||||
|
put '<Type>Tree</Type>' ;
|
||||||
|
put '<NS>SAS</NS>' ;
|
||||||
|
put '<Flags>388</Flags>' ;
|
||||||
|
put '<Options>' ;
|
||||||
|
put '<XMLSelect search="Tree[SoftwareComponents/SoftwareComponent'@;
|
||||||
|
put '[@Name=''BIP Service'']]"/>';
|
||||||
|
put '</Options>' ;
|
||||||
|
put '</GetMetadataObjects>' ;
|
||||||
|
run ;
|
||||||
|
proc metadata in=&fname1 out=&fname2 verbose;run;
|
||||||
|
|
||||||
|
/* create an XML map to read the response */
|
||||||
|
data _null_;
|
||||||
|
file &fname3;
|
||||||
|
put '<SXLEMAP version="1.2" name="SASFolders">';
|
||||||
|
put '<TABLE name="SASFolders">';
|
||||||
|
put '<TABLE-PATH syntax="XPath">//Objects/Tree</TABLE-PATH>';
|
||||||
|
put '<COLUMN name="metauri">><LENGTH>17</LENGTH>';
|
||||||
|
put '<PATH syntax="XPath">//Objects/Tree/@Id</PATH></COLUMN>';
|
||||||
|
put '<COLUMN name="metaname"><LENGTH>256</LENGTH>>';
|
||||||
|
put '<PATH syntax="XPath">//Objects/Tree/@Name</PATH></COLUMN>';
|
||||||
|
put '</TABLE></SXLEMAP>';
|
||||||
|
run;
|
||||||
|
%local libref1;
|
||||||
|
%let libref1=%mf_getuniquelibref();
|
||||||
|
libname &libref1 xml xmlfileref=&fname2 xmlmap=&fname3;
|
||||||
|
|
||||||
|
data &outds;
|
||||||
|
length metatype $32;
|
||||||
|
retain metatype 'Folder';
|
||||||
|
set &libref1..sasfolders;
|
||||||
|
run;
|
||||||
|
|
||||||
|
%end;
|
||||||
|
%else %do;
|
||||||
|
%mm_getfoldertree(root=&root, outds=&outds,depth=1)
|
||||||
|
data &outds;
|
||||||
|
set &outds(rename=(name=metaname publictype=metatype));
|
||||||
|
keep metaname metauri metatype;
|
||||||
|
run;
|
||||||
|
%end;
|
||||||
|
|
||||||
|
%mend;
|
||||||
|
/**
|
||||||
|
@file
|
||||||
@brief Returns all folders / subfolder content for a particular root
|
@brief Returns all folders / subfolder content for a particular root
|
||||||
@details Shows all members and SubTrees recursively for a particular root.
|
@details Shows all members and SubTrees recursively for a particular root.
|
||||||
Note - for big sites, this returns a lot of data! So you may wish to reduce
|
Note - for big sites, this returns a lot of data! So you may wish to reduce
|
||||||
the logging to speed up the process (see example below)
|
the logging to speed up the process (see example below), OR - use mm_tree.sas
|
||||||
|
which uses proc metadata and is far more efficient.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
options ps=max nonotes nosource;
|
options ps=max nonotes nosource;
|
||||||
%mm_getfoldertree(root=/My/Meta/Path, outds=iwantthisdataset)
|
%mm_getfoldertree(root=/My/Meta/Path, outds=iwantthisdataset)
|
||||||
options notes source;
|
options notes source;
|
||||||
|
|
||||||
@param root= the parent folder under which to return all contents
|
@param [in] root= the parent folder under which to return all contents
|
||||||
@param outds= the dataset to create that contains the list of directories
|
@param [out] outds= the dataset to create that contains the list of directories
|
||||||
@param mDebug= set to 1 to show debug messages in the log
|
@param [in] mDebug= set to 1 to show debug messages in the log
|
||||||
|
|
||||||
<h4> SAS Macros </h4>
|
<h4> SAS Macros </h4>
|
||||||
|
|
||||||
@@ -8166,7 +8263,7 @@ data &outds.TMP/view=&outds.TMP;
|
|||||||
__n1+1;
|
__n1+1;
|
||||||
/* Walk through all possible associations of this object. */
|
/* Walk through all possible associations of this object. */
|
||||||
__n2=1;
|
__n2=1;
|
||||||
if assoctype in ('Members','SubTrees') then
|
if assoctype in ('Members','SubTrees') then
|
||||||
do while(metadata_getnasn(pathuri,assoctype,__n2,metauri)>0);
|
do while(metadata_getnasn(pathuri,assoctype,__n2,metauri)>0);
|
||||||
__n2+1;
|
__n2+1;
|
||||||
call missing(name,publictype,MetadataUpdated,MetadataCreated);
|
call missing(name,publictype,MetadataUpdated,MetadataCreated);
|
||||||
|
|||||||
95
meta/mm_getfoldermembers.sas
Normal file
95
meta/mm_getfoldermembers.sas
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
/**
|
||||||
|
@file
|
||||||
|
@brief Returns all direct child members of a particular folder
|
||||||
|
@details Displays the children for a particular folder, in a similar fashion
|
||||||
|
to the viya counterpart (mv_getfoldermembers.sas)
|
||||||
|
|
||||||
|
Usage:
|
||||||
|
|
||||||
|
%mm_getfoldermembers(root=/, outds=rootfolders)
|
||||||
|
|
||||||
|
%mm_getfoldermembers(root=/User Folders/&sysuserid, outds=usercontent)
|
||||||
|
|
||||||
|
@param [in] root= the parent folder under which to return all contents
|
||||||
|
@param [out] outds= the dataset to create that contains the list of directories
|
||||||
|
@param [in] mDebug= set to 1 to show debug messages in the log
|
||||||
|
|
||||||
|
<h4> Data Outputs </h4>
|
||||||
|
|
||||||
|
Example for `root=/`:
|
||||||
|
|
||||||
|
|metauri $17|metaname $256|metatype $32|
|
||||||
|
|---|---|---|
|
||||||
|
|A5XLSNXI.AA000001|Products |Folder|
|
||||||
|
|A5XLSNXI.AA000002|Shared Data |Folder|
|
||||||
|
|A5XLSNXI.AA000003|User Folders |Folder|
|
||||||
|
|A5XLSNXI.AA000004|System |Folder|
|
||||||
|
|A5XLSNXI.AA00003K|30.SASApps |Folder|
|
||||||
|
|A5XLSNXI.AA00006A|Public|Folder|
|
||||||
|
|
||||||
|
<h4> SAS Macros </h4>
|
||||||
|
@li mm_getfoldertree.sas
|
||||||
|
@li mf_getuniquefileref.sas
|
||||||
|
@li mf_getuniquelibref.sas
|
||||||
|
|
||||||
|
@version 9.4
|
||||||
|
@author Allan Bowe
|
||||||
|
|
||||||
|
**/
|
||||||
|
%macro mm_getfoldermembers(
|
||||||
|
root=
|
||||||
|
,outds=work.mm_getfoldertree
|
||||||
|
)/*/STORE SOURCE*/;
|
||||||
|
|
||||||
|
%if "&root" = "/" %then %do;
|
||||||
|
%local fname1 fname2 fname3;
|
||||||
|
%let fname1=%mf_getuniquefileref();
|
||||||
|
%let fname2=%mf_getuniquefileref();
|
||||||
|
%let fname3=%mf_getuniquefileref();
|
||||||
|
data _null_ ;
|
||||||
|
file &fname1 ;
|
||||||
|
put '<GetMetadataObjects>' ;
|
||||||
|
put '<Reposid>$METAREPOSITORY</Reposid>' ;
|
||||||
|
put '<Type>Tree</Type>' ;
|
||||||
|
put '<NS>SAS</NS>' ;
|
||||||
|
put '<Flags>388</Flags>' ;
|
||||||
|
put '<Options>' ;
|
||||||
|
put '<XMLSelect search="Tree[SoftwareComponents/SoftwareComponent'@;
|
||||||
|
put '[@Name=''BIP Service'']]"/>';
|
||||||
|
put '</Options>' ;
|
||||||
|
put '</GetMetadataObjects>' ;
|
||||||
|
run ;
|
||||||
|
proc metadata in=&fname1 out=&fname2 verbose;run;
|
||||||
|
|
||||||
|
/* create an XML map to read the response */
|
||||||
|
data _null_;
|
||||||
|
file &fname3;
|
||||||
|
put '<SXLEMAP version="1.2" name="SASFolders">';
|
||||||
|
put '<TABLE name="SASFolders">';
|
||||||
|
put '<TABLE-PATH syntax="XPath">//Objects/Tree</TABLE-PATH>';
|
||||||
|
put '<COLUMN name="metauri">><LENGTH>17</LENGTH>';
|
||||||
|
put '<PATH syntax="XPath">//Objects/Tree/@Id</PATH></COLUMN>';
|
||||||
|
put '<COLUMN name="metaname"><LENGTH>256</LENGTH>>';
|
||||||
|
put '<PATH syntax="XPath">//Objects/Tree/@Name</PATH></COLUMN>';
|
||||||
|
put '</TABLE></SXLEMAP>';
|
||||||
|
run;
|
||||||
|
%local libref1;
|
||||||
|
%let libref1=%mf_getuniquelibref();
|
||||||
|
libname &libref1 xml xmlfileref=&fname2 xmlmap=&fname3;
|
||||||
|
|
||||||
|
data &outds;
|
||||||
|
length metatype $32;
|
||||||
|
retain metatype 'Folder';
|
||||||
|
set &libref1..sasfolders;
|
||||||
|
run;
|
||||||
|
|
||||||
|
%end;
|
||||||
|
%else %do;
|
||||||
|
%mm_getfoldertree(root=&root, outds=&outds,depth=1)
|
||||||
|
data &outds;
|
||||||
|
set &outds(rename=(name=metaname publictype=metatype));
|
||||||
|
keep metaname metauri metatype;
|
||||||
|
run;
|
||||||
|
%end;
|
||||||
|
|
||||||
|
%mend;
|
||||||
@@ -1,18 +1,20 @@
|
|||||||
/**
|
/**
|
||||||
@file mm_getfoldertree.sas
|
@file
|
||||||
@brief Returns all folders / subfolder content for a particular root
|
@brief Returns all folders / subfolder content for a particular root
|
||||||
@details Shows all members and SubTrees recursively for a particular root.
|
@details Shows all members and SubTrees recursively for a particular root.
|
||||||
Note - for big sites, this returns a lot of data! So you may wish to reduce
|
Note - for big sites, this returns a lot of data! So you may wish to reduce
|
||||||
the logging to speed up the process (see example below)
|
the logging to speed up the process (see example below), OR - use mm_tree.sas
|
||||||
|
which uses proc metadata and is far more efficient.
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
options ps=max nonotes nosource;
|
options ps=max nonotes nosource;
|
||||||
%mm_getfoldertree(root=/My/Meta/Path, outds=iwantthisdataset)
|
%mm_getfoldertree(root=/My/Meta/Path, outds=iwantthisdataset)
|
||||||
options notes source;
|
options notes source;
|
||||||
|
|
||||||
@param root= the parent folder under which to return all contents
|
@param [in] root= the parent folder under which to return all contents
|
||||||
@param outds= the dataset to create that contains the list of directories
|
@param [out] outds= the dataset to create that contains the list of directories
|
||||||
@param mDebug= set to 1 to show debug messages in the log
|
@param [in] mDebug= set to 1 to show debug messages in the log
|
||||||
|
|
||||||
<h4> SAS Macros </h4>
|
<h4> SAS Macros </h4>
|
||||||
|
|
||||||
@@ -60,7 +62,7 @@ data &outds.TMP/view=&outds.TMP;
|
|||||||
__n1+1;
|
__n1+1;
|
||||||
/* Walk through all possible associations of this object. */
|
/* Walk through all possible associations of this object. */
|
||||||
__n2=1;
|
__n2=1;
|
||||||
if assoctype in ('Members','SubTrees') then
|
if assoctype in ('Members','SubTrees') then
|
||||||
do while(metadata_getnasn(pathuri,assoctype,__n2,metauri)>0);
|
do while(metadata_getnasn(pathuri,assoctype,__n2,metauri)>0);
|
||||||
__n2+1;
|
__n2+1;
|
||||||
call missing(name,publictype,MetadataUpdated,MetadataCreated);
|
call missing(name,publictype,MetadataUpdated,MetadataCreated);
|
||||||
|
|||||||
Reference in New Issue
Block a user