Hi All,
I have 26 datasets in a folder and i wanted to convert all of them into XPT at one go.
Can any one help me with a macro ?
@r3570 wrote:
Hi Tom,
I was able to create a single xpt file which included all the datasets in
it using proc copy.
Because it is hectic task to write 26 programs for each dataset to convert
into xpt, I need a macro which creates xpt file separately for each dataset
in one go.
If you can place all the data sets into one file what is the advantage of creating 26 files?
Have you tried using the XPORT engine in the LIBNAME statement? Here's some documentation:
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/movefile/p07no93eh1e7oun1fmp0anvi7k3k.htm
I'm assuming you would know how to make a macro out of something like this. There's also this article, but I didn't give it much of a read. There's a section specifically dedicated toward a macro.
https://www.lexjansen.com/pharmasug/2004/FDACompliance/FC07.pdf
Yes i know hoe to convert a single dataset in xpt file using xport in libname statement. but not able to figure out how to convert all the datasets at a time instead of doing it one by one.
/*************一个SAS数据集 转成 一个XPT文件************/ /* path to store xpt file*/ %let path_out= D:\XiaKeShan\my_code\数据管理\转XPT文件\XPT ; /* path to address sas dataset*/ %let path_in= D:\XiaKeShan\my_code\数据管理\转XPT文件\SAS ; /*transform a sas file into a xpt dataset*/ libname in v9 "&path_in"; data _null_; rc=filename('x',"&path_in"); did=dopen('x'); do i=1 to dnum(did); memname=dread(did,i); call execute(cat("libname tranfile xport '&path_out\",scan(memname,1,'.'),".xpt';proc copy in=in out=tranfile;select ",scan(memname,1,'.'),";run;")); end; run;
Here is V5 version XPT file.
Here is V8 version XPT file .
/*************一个SAS数据集 转成 一个XPT文件************/ /* path to store xpt file*/ %let path_out= D:\XiaKeShan\my_code\数据管理\转XPT文件\XPT ; /* path to address sas dataset*/ %let path_in= D:\XiaKeShan\my_code\数据管理\转XPT文件\SAS ; /*transform a sas file into a xpt dataset*/ libname in v9 "&path_in"; data _null_; rc=filename('x',"&path_in"); did=dopen('x'); do i=1 to dnum(did); memname=dread(did,i); call execute(cas("%loc2xpt(libref=in,memlist=",scan(memname,1,'.'),",filespec=&path_out\",scan(memname,1,'.'),".xpt)")); end; run;
Do you want one XPT file with all 26 datasets in it?
Or a separate XPT file for each dataset?
Or some other combination?
What type of file to you want to create? XPT does not have a fixed meaning. SAS can make CPORT files using PROC CPORT or you can make XPORT files using XPORT engine (for V5 compatible datasets) or the %LOC2XPT() macro for datasets that use features not supported by version 5 SAS datasets.
Inputs are probably the libref (or optionally the path) to where to find the datasets and the path for writing the XPT files. Another optional input might be a list of members or logic for how to select the members.
Get the list of members.
proc contents data=&libref.._all_ noprint out=contents; run;
Use the list to generate the code to create the XPORT files.
data _null_;
set contents;
by memname;
if first.memname;
call execute(catx(' '
,'libname out xport',quote(catx('/',"&targetdir",cats(lowcase(memname),'.xpt'))),';'
,'proc copy inlib=',libname,'outlib=out;','select',nliteral(memname),';run;'
));
run;
@r3570 wrote:
Hi Tom,
I was able to create a single xpt file which included all the datasets in
it using proc copy.
Because it is hectic task to write 26 programs for each dataset to convert
into xpt, I need a macro which creates xpt file separately for each dataset
in one go.
If you can place all the data sets into one file what is the advantage of creating 26 files?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.