I want

Reply
Contributor
Posts: 34

I want

Hi All,

I have SASDATA SET in library , 20 dataset. so i need to convert them in to .xpt files? 

This works for single file :

%let datafile = set2 ;

libname input 'C:\Documents and Settings\Desktop\New Folder';

libname output xport 'C:\Documents and Settings\Desktop\New Folder\&datafile..xpt';

proc copy in=input out=output;

select &datafile. ;

run;

Some help me for nth number of SAS DATA SETS in LIBRARY

Thanks,

Super User
Super User
Posts: 7,720

Re: I want

Hi,

filename tmp pipe 'dir "C:\Documents and Settings\Desktop\New Folder\*.xpt" /b';

data _null_;

     length buffer $varying256;

     infile tmp;

     input buffer $;

     call execute(' libname input "C:\Documents and Settings\Desktop\New Folder";

                              libname output xport "C:\Documents and Settings\Desktop\New Folder\'||strip(buffer)||'";

                              proc copy in=input out=output;

                              run;');

run;


Edit: As KurtBremser has just pointed out, you are writing out from SAS, not reading in, sorry I miread the question.  Indeed, change to:

data _null_;

     set sashelp.vtable (where=(libname="your_libname"));

     call execute(' libname input "C:\Documents and Settings\Desktop\New Folder";

                              libname output xport "C:\Documents and Settings\Desktop\New Folder\'||strip(name)||'";

                              proc copy in=input out=output;

                                   select '||strip(name)||';

                              run;');

run;

Super User
Posts: 7,435

Re: I want

Wrap your code into a macro that has datafile as parameter.

Then write a data _null_ step that obtains the membernames from sashelp.vtable and uses call execute to call the macro for each table in the library.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 34

Re: I want

Can you please help me with macro code :smileyshocked:r basic  IDEA.

Trusted Advisor
Posts: 1,137

Re: I want

Hi Anita,

Here is another method

%macro sas2xpt(in,outfolder);

  libname _sas2xpt ∈

  proc sql noprint;

    create table _sas2cont as

    (select memname from dictionary.tables

     where libname="_SAS2XPT" and memtype="DATA"

     ) order by memname;

  quit;

  data test;

    retain outxpt &outfolder;

    set _sas2cont;

    call execute("libname _xptout xport %nrstr('"||trim(outxpt)||trim(memname)||".xpt');");

    call execute('proc copy in=_sas2xpt out=_xptout;select '||trim(memname)||';run;');

    call execute('libname _xptout clear;');

  run;

  libname _sas2xpt clear;

  proc datasets nolist memtype=data;

    delete _sas2cont;

  run;

  quit;

%mend sas2xpt;                                                       

options nosymbolgen nomlogic mprint;

%sas2xpt("Path",%nrstr("Path\"));

Thanks,
Jag
Super User
Super User
Posts: 6,845

Re: I want

Note that XPORT engine only supports datasets that conform to older SAS V5 standards.  So variable names are limited to 8 characters.  Character variables are limited 200 characters.  Labels are limited to 40 characters.


This is the simplest macro type to write.  One where you already have a working piece of SAS code and just want to replace parts of it with value that changes. In this case the table name.

Note that to get macro variable reference &DATAFILE to expand you need to double quote characters instead of single quote characters to quote the path name.


%macro xport(DATAFILE);

libname output xport "C:\Documents and Settings\Desktop\New Folder\&datafile..xpt";

proc copy in=input out=output;

select &datafile. ;

run;

libname output clear ;

%mend xport;

You can get a list of datasets in the library INPUT from SAS metadata in a number of ways.  You could use PROC CONTENTS or query on the views that SQL provides.  Some of the views are also available as in the SASHELP library.

Trusted Advisor
Posts: 1,301

Re: I want

%macro anitapamu2(in_dir=,out_dir=&in_dir.);

%local rc;

%let rc=%sysfunc(libname(in, &in_dir.));

%local dsid memname;

%let dsid=%sysfunc(open(sashelp.vtable(where=(libname='IN')),is));

%syscall set(dsid);

%do %while(%sysfunc(fetch(&dsid))=0);

libname out xport "&out_dir./%trim(&memname.).xpt";

proc copy in=in out=out;

   select &memname.;

   run;

quit;

libname out clear;

%end;

%let rc=%sysfunc(close(&dsid.));

%let rc=%sysfunc(libname(in));

%mend;

data foo;

do i=1 to 10;

output;

end;

run;

%anitapamu2(in_dir=%sysfunc(pathname(work,l)))

Super User
Posts: 11,134

Re: I want

Is there any reason not to use CPORT to create one transport file containing all of the data sets?

if not

proc cport library=yourlib file="pathtofile\transport file name.xpt";run;

or use a File ref.

Ask a Question
Discussion stats
  • 7 replies
  • 350 views
  • 2 likes
  • 7 in conversation