BookmarkSubscribeRSS Feed
paddyb
Quartz | Level 8

I have a folder in sas studio with multiple xpt files.How to convert it into sas datasets?I can do it choosing each file in to a dataset but how to make it dynamic?

5 REPLIES 5
SASKiwi
PROC Star

Start by getting the import for one file working properly first. Here is a link to the CIMPORT procedure to get you started:

 

http://support.sas.com/documentation/cdl/en/proc/69850/HTML/default/viewer.htm#p1be86uw07acoin1aodzs...

 

A dynamic solution will most likely involve building a macro.

paddyb
Quartz | Level 8

libname xylib xport "/home/p0/AM2/data/agxpt/*.xpt ";
proc copy in=xylib out=work;
run;

I tried this to convert all xpt files frm agxpt folder but only 4 files i see converted into dataset.Folder have 7 files.Any idea why?

Bhavanaa
Calcite | Level 5

this didn't work when i am trying to extract multiple XPT files to SAS files.

Tom
Super User Tom
Super User

The XPORT engine works on a single file.

Tom
Super User Tom
Super User

Step one figure out if your XPT files are SAS V5 transport files, CPORT files or possibly the new V7 transport files that require using the SAS published macro to read.  Then get the code to convert one file.  So for a V5 transport file the code copy all of the dataset that are in the transport file to SAS datasets would look like this:

libname out "path";
libname in xport "filename";
proc copy inlib=in outlib=out;
run;

Where filename is the name of the XPT file and path is the directory where you want to write the files. To copy them as work datasets skip the first libname statement and just use WORK as the outlib in the proc copy step.

 

If the file was generated by PROC CPORT then you need to generate a PROC CIMPORT step instead.

 

Now get a list of the files.  There are tons of posts on this site for how to do that.

 

Then either use the list to generate the LIBNAME,PROC COPY steps.  For example if your list of filenames is in a data set named FILES and the variable with the filename is named FILENAME then that code could look like this:

filename code temp;
data _null_;
  set files ;
  file code ;
  put
  'libname in xport ' filename :$quote. ';'
/ 'proc copy inlib=in outlib=out; run; '
  ;
run;
%include code / source2 ;

Or you could create a little macro to do one file and generate the code to call the macro. 

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

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
  • 5 replies
  • 7968 views
  • 0 likes
  • 4 in conversation