Macro %xpt_converter
1. Description
The macro CONVERT is used for converting SAS datasets to XPT files.
2. Dependencies
2.1 Global Macro Variables - N/A
2.2 Global Macros - N/A
3. Macro Parameters
Macro parameter | Description | Example |
---|---|---|
INLIB (R) | The library/Directory or path of folders where SAS datasets exists and ready to be converted into XPT files. | INLIB= RAW ,Default value: None |
(R): Required
4. Assumptions
N/A
5. Sample Call
%CONVERT(INLIB= RAW);
6. Macro Code
%macro Convert(inlib);
%*--- Test case1: if inlib is missing;
%if &inlib eq %then %do;
%put ISSUE FOUND: Macro parameter 'inlib' is not specified;
%goto exit;
%end;
%else %do;
%*--- Test case2: if invalid library specified;
%if %sysfunc(libref(&inlib)) ne 0 %then %do;
%put ISSUE FOUND: Invalid library specified;
%goto exit;
%end;
%else %do;
%let all_data = _null_;
proc sql noprint ;
select distinct memname into: all_data separated by " "
from sashelp.vtable
where find(libname,"&inlib.","i")=1;
quit;
%*--- Test case3: if library is empty;
%if &all_data eq _null_ %then %do;
%put ISSUE FOUND: Library &inlib. is empty;
%goto exit;
%end;
%else %do;
%do i=1 %to %sysfunc(countw(&all_data));
%local data_nm;
%let data_nm = %scan(&all_data, &i," ");
%let libpath = %sysfunc(pathname(&inlib.));
libname xptfile XPORT "&libpath\&data_nm..xpt";
proc copy in=&inlib. out=xptfile memtype=data;
select &data_nm.;
run;
%end;
%end;
%end;
%end;
%exit:
%mend Convert;