BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sam369
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

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

6 REPLIES 6
SGB
Obsidian | Level 7 SGB
Obsidian | Level 7

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

sam369
Obsidian | Level 7

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


art297
Opal | Level 21

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;

sam369
Obsidian | Level 7

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

art297
Opal | Level 21

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


LetourneauKent
Calcite | Level 5

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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 45142 views
  • 10 likes
  • 4 in conversation