- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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 ?
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
/*************一个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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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?