Hi ,
I wanted to know, what all the xpt files (only) available in the particular library.
anyone know how to find it.
Thanks,
Abhinay
Use the BasePlus package and the %dirsAndFiles() macro
For example like this:
%dirsAndFiles(
C:\SAS_WORK /* directory to search (includes subdirs.) */
,ODS=work.result
,fileExt=xpt /* file extension */
)
Bart
P.S. Here are some instructions how to get BasePlus package and where the documentation is.
/*
Details about SAS Packages Framework:
- https://github.com/yabwon/SAS_PACKAGES
Tutorial:
- https://github.com/yabwon/HoW-SASPackages
BasePlus documentation:
- https://github.com/SASPAC/macroarray/blob/main/baseplus.md
*/
/* Step 1. */
/* Install SAS Packages Framework and BasePlus package. */
/* Run this only once. */
filename SPFinit url "https://bit.ly/SPFinit";
%include SPFinit;
filename SPFinit clear;
/* create directory for the framework and packages */
filename packages "</your/directory/for/packages/>";
/* install the framework and the BasePlus package */
%installPackage(SPFinit BasePlus)
/* Step 2. */
/* From now on if you want to use a package: */
/* Run this at the beginning of your new SAS Session (or add it to autoexec). */
/* Enable framework and load package */
filename packages "</your/directory/for/packages/>";
%include packages(SPFinit.sas);
%loadPackage(BasePlus)
I think you can use the SAS directory functions to list the files, e.g.:
data ExportFiles;
rc=filename("mydir", "<physical file name>");
did=dopen("mydir");
if did > 0 then do;
do _N_=1 to dnum(did);
fname=dread(did,_N_);
if upcase(scan(fname,-1,'.')) = 'XPT' then output;
end;
rc=dclose(did);
end;
else do;
msg=sysmsg();
put msg;
end;
keep fname;
run;
What do you mean by LIBRARY?
In SAS you can use the LIBNAME statement to make a library to points to where SAS datasets and other SAS objects are stored.
But an XPT file is NOT a SAS object that would be stored in such a library.
If you mean a directory of files (what some call a "folder") then just use normal tools for listing the files in a directory. This question has been asked many times. Here is one: https://communities.sas.com/t5/SAS-Programming/SAS-Macro-to-Check-Each-Subfolder-Within-a-Directory-...
Note that you will also need to take care once you have the list of XPT files as that extension has no fixed meaning. It could be a SAS V5 Xport file produced by the XPORT libref engine. It could be a transport file produced by PROC CPORT. It could be a SAS V7/8/9 Xport file produced by the %LOC2XPT() system macro. Or could be something that is not at all related to SAS.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.