Explanation : Main Data Step that queries the metadata. It uses `metadata_resolve` to identify objects, then loops through the results. For each directory (`Directory`), it retrieves the path (`DirectoryName`) and explores the `Files` association to get file names. For `SASFileRef` objects, it directly retrieves the `Name` attribute. Full paths are stored in the `fqn` variable.
Copied!
data directories;
/* Initialize variables. */
length type id dir_uri file_uri $ 50 path file_name fqn $ 255;
call missing(of _character_);
keep fqn;
/* Define a query to find all directory objects */
obj="omsobj:Directory?Directory[Files/File[ @code_sas_json/downside_frequency_test.json contains '.']";
/* Count the objects that match this query. */
dir_count=metadata_resolve(obj,type,id);
/* Proceed if any directories are found. */
if dir_count > 0 then do i=1 to dir_count;
rc=metadata_getnobj(obj,i,dir_uri);
rc=metadata_getattr(dir_uri,"DirectoryName",path);
/* Find the files associated with the path. */
file_count=metadata_getnasn(dir_uri,"Files",1,file_uri);
if file_count > 0 then do j=1 to file_count;
rc=metadata_getnasn(dir_uri,"Files",j,file_uri);
rc=metadata_getattr(file_uri,"FileName",file_name);
fqn=catx("/",path,file_name);
output;
end;
end;
/* Define a search query to find any "SASFileRef" object types. */
obj2="omsobj:SASFileRef? @code_sas_json/downside_frequency_test.json contains '.'";
fileref_count=metadata_resolve(obj2,type,id);
if fileref_count > 0 then do i = 1 to fileref_count;
rc=metadata_getnobj(obj2,i,file_uri);
rc=metadata_getattr(file_uri,"Name",fqn);
output;
end;
run;
1
DATA directories;
2
3
/* Initialize variables. */
4
LENGTH type id dir_uri file_uri $ 50 path file_name fqn $ 255;
5
call missing(of _character_);
6
keep fqn;
7
8
/* Define a query to find all directory objects */
IF fileref_count > 0 THENDO i = 1 to fileref_count;
32
rc=metadata_getnobj(obj2,i,file_uri);
33
rc=metadata_getattr(file_uri,"Name",fqn);
34
OUTPUT;
35
END;
36
37
RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
« This inventory is the first step in identifying "ghost files"—metadata references pointing to files that have been deleted from the physical disk. To take this a step further, consider pairing this script with the fileexist() function to immediately validate the physical presence of every resource found. »
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.