Help using Base SAS procedures

How To create .XPT files? How to Convert .xpt files to Sas Dataset

Accepted Solution Solved
Reply
Regular Contributor
Posts: 168
Accepted Solution

How To create .XPT files? How to Convert .xpt files to Sas Dataset

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


Accepted Solutions
Solution
‎08-13-2012 12:20 PM
PROC Star
Posts: 7,363

Re: How To create .XPT files? How to Convert .xpt files to Sas Dataset

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;

View solution in original post


All Replies
Contributor SGB
Contributor
Posts: 41

Re: How To create .XPT files? How to Convert .xpt files to Sas Dataset

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

Regular Contributor
Posts: 168

Re: How To create .XPT files? How to Convert .xpt files to Sas Dataset

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


Solution
‎08-13-2012 12:20 PM
PROC Star
Posts: 7,363

Re: How To create .XPT files? How to Convert .xpt files to Sas Dataset

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;

Regular Contributor
Posts: 168

Re: How To create .XPT files? How to Convert .xpt files to Sas Dataset

Thank you Art!!!!
But i was bit confused with "code2run"? got you able to explain me !! i will be helpful!!!

PROC Star
Posts: 7,363

Re: How To create .XPT files? How to Convert .xpt files to Sas Dataset

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


Occasional Learner
Posts: 1

Re: How To create .XPT files? How to Convert .xpt files to Sas Dataset

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

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 6 replies
  • 15739 views
  • 6 likes
  • 4 in conversation