Hi All,
I have data library . in this library i have 20 dataset. so i need to convert them in to .xpt files? how can i do that
i have 15 .xpt files .so need to convert them into sas dataset files.
can somebody explain with example
THanks
Sam
Sam,
There is probably an easier, more direct way to do what you want, but you can always simply build and run an include file substituting the desired information where needed. e.g.,:
%let path=c:;
filename indata pipe "dir &path.\*.sas7bdat /b";
filename code2run temp;
data _null_;
length fil2xpt xpt2xpt $420;
infile indata truncover;
file code2run;
/* Read the filenames identified by your system's */
/* directory command */
informat filenm $100.;
input filenm &;
/* The following statement concatenates &path with each */
/* filename */
fil2xpt=scan(filenm,1,".");
xpt2xpt=cats("libname xptfile xport '&path.\",fil2xpt,".xpt';");
put "libname sasfile '&path.';";
put xpt2xpt;
put 'proc copy in = sasfile out = xptfile;';
put 'select ';
put fil2xpt;
put '; run;';
put 'libname sasfile clear;';
put 'libname xptfile clear;';
put 'run;';
run;
%include code2run;
You can use PROC COPY with XPORT to do this. You can also use PROC CPORT.
libname sasfile 'c:\documents\mylib';
libname xptfile XPORT 'c:\documents\file1.xpt';
proc copy in = sasfile out = xptfile;
select file1;
run;
SGB
Thank you SGB!!!!!
I know how to do by single .XPT file, But i want to know instead of passing single .XPT file , by using array or something else to pick all the .XPT files from the folder.
Thanks for you Reply
Sam
Sam,
There is probably an easier, more direct way to do what you want, but you can always simply build and run an include file substituting the desired information where needed. e.g.,:
%let path=c:;
filename indata pipe "dir &path.\*.sas7bdat /b";
filename code2run temp;
data _null_;
length fil2xpt xpt2xpt $420;
infile indata truncover;
file code2run;
/* Read the filenames identified by your system's */
/* directory command */
informat filenm $100.;
input filenm &;
/* The following statement concatenates &path with each */
/* filename */
fil2xpt=scan(filenm,1,".");
xpt2xpt=cats("libname xptfile xport '&path.\",fil2xpt,".xpt';");
put "libname sasfile '&path.';";
put xpt2xpt;
put 'proc copy in = sasfile out = xptfile;';
put 'select ';
put fil2xpt;
put '; run;';
put 'libname sasfile clear;';
put 'libname xptfile clear;';
put 'run;';
run;
%include code2run;
Thank you Art!!!!
But i was bit confused with "code2run"? got you able to explain me !! i will be helpful!!!
The easiest explanation would be for you to have SAS write the code out to a permanent file so that you can see what was actually produced by the code. You can do that by simply changing the filename statement from:
filename code2run temp;
to something like: filename code2run "c:\code2run.sas";
Assuming you are on windows, the code uses the dir command to create a file that lists all of your datasets that reside in the specified directory. Then, for each one, it writes out the proc copy command, filling in all of the needed file and directory names.
Art
I have been using the PROC COPY method to create sas v5 XPT transport files for years to transfer data to the FDA. It has recently been pointed out the the
https://support.sas.com/techsup/technote/ts140.pdf tech notes for this format state that the
INTRODUCTION
All transport data set records are 80 bytes in length. If there is not sufficient
data to reach 80 bytes, then a record is padded with ASCII blanks to 80 bytes. All
character data are stored in ASCII, regardless of the operating system.
I am working in a SAS environment with wlatin1 encoding and often my data contains characters that are not part of the ascii character set. When I create my XPT files with the PROC COPY method described in this thread I get SAS v5 XPT files but these files still contain my wlatin1 encoding.
Is it possible that the SAS logic to create a SAS v5 XPT files creates files that are not fully compliant with their own technotes or am I misunderstanding something?
thanks in advance for hte responses.
KL
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 the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.