Here's a piece of code I've had for years, and about every six months I use it in a response on the communities.
It's way over designed for what you want, it pulls in all of the files in a directory, and then for each file picks up all of the attributes, but you should be able to see the necessary bits.
I just tried it, and it still works, but I have a Windows machine and no access to Unix. Give it a try. The only thing you should need to change is the directory on the first line.
Tom
/* Set the directory name to scan */
%let DirectoryName = C:\directory;
data DatasetsInADirectory;
keep DirectoryAndDataset;
length DatasetName DirectoryAndDataset $1024 FileRef $8;
/* Assign the fileref */
call missing(FileRef); /* Blank, so SAS will assign a file name */
rc1 = filename(FileRef, "&DirectoryName."); /* Associate the file name with the directory */
if rc1 ^= 0 then
abort;
/* Open the directory for access by SAS */
DirectoryID = dopen(FileRef);
if DirectoryID = 0 then
abort;
/* Get the count of directories and datasets */
MemberCount = dnum(DirectoryID);
if MemberCount = 0 then
abort;
/* Get all of the entry names ... directories and datasets */
do MemberIndex = 1 to MemberCount;
DatasetName = dread(DirectoryID, MemberIndex);
if missing(DatasetName) then
abort;
DirectoryAndDataset = cats("&DirectoryName.","/",DatasetName);
output;
end;
/* Close the directory */
rc2 = dclose(DirectoryID);
if rc2 ^= 0 then
abort;
run;
data Attributes;
keep DirectoryAndDataset OptionName OptionVal;
length EntryType $12 FileRef $8 OptionName $20 OptionVal $1024;
set DatasetsInADirectory;
/* Assign the fileref */
call missing(FileRef); /* Blank, so SAS will assign a file name */
rc1 = filename(FileRef, DirectoryAndDataset); /* Associate the file name with the dataset or directory */
if rc1 ^= 0 then
abort;
/* Open the entry for access by SAS. If it is a directory, zero will be returned */
EntryID = fopen(FileRef);
/* Process the entries */
if EntryID = 0
then do;
EntryType = "Directory";
output;
end;
else do;
/* Get the number of options for the dataset */
OptNum = foptnum(EntryID);
if OptNum = . then
abort;
EntryType = "Dataset";
/* Get all of the options for the dataset */
do OptCount = 1 to OptNum;
OptionName = foptname(EntryID, OptCount);
OptionVal = finfo(EntryID, OptionName);
output;
end;
/* Close the directory */
rc2 = fclose(EntryID);
if rc2 ^= 0 then
abort;
end;
run;
proc sql;
drop table DatasetsInADirectory;
quit;
... View more