DATA Step, Macro, Functions and more

Convert multiple xpt to sas files

Reply
Frequent Contributor
Frequent Contributor
Posts: 106

Convert multiple xpt to sas files

[ Edited ]

hi All,

 

I am using the code below to convert xpt files to sas files.

However, I see the following error message "ERROR: Libref XPTFILE is not assigned."

Any leadss to resolve this issue?

 

Thanks

 

%let path=E:\data\source;
filename xptfiles pipe "dir /b ""&path\%str(*).xpt"" " ;
filename code temp;
data files;
infile xptfiles truncover;
input filename $100. ;
file code;
put 'filename xptfile "&path\' filename +(-1) '" ;';
put 'proc copy inlib=xptfile outlib=ms; run;' ;
run;
libname ms 'E:\data\SAS datasets';
%inc code / source2 ;


 

Super User
Super User
Posts: 9,441

Re: Convert multiple xpt to sas files

Something like:

filename tmp pipe 'dir "c:/mypath/*.xpt" /b";

libname ms "c:/wanttokeeparea";

data _null_;
  infile tmp;
  input;
  call execute(cats('filename xptfile "c:/mypath/',_input_,'"));
  call execute('proc copy inlib=xptfile outlib=ms; run;');
call execute('filename xptfile clear;'); run;
Super User
Posts: 9,924

Re: Convert multiple xpt to sas files

In preparation for proc copy, use a libname instead of a filename statement. Proc copy is for libraries and not file references.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Frequent Contributor
Frequent Contributor
Posts: 106

Re: Convert multiple xpt to sas files

@Tom; Any comments?

Super User
Super User
Posts: 7,941

Re: Convert multiple xpt to sas files

@KurtBremser has already given you the answer.

Super User
Posts: 5,852

Re: Convert multiple xpt to sas files

Just a thought, given the filename extension, perhaps this file should be read by either PROC CIMPORT or the libname xport engine?
Data never sleeps
Ask a Question
Discussion stats
  • 5 replies
  • 438 views
  • 0 likes
  • 5 in conversation