Hi,
I am trying to create a macro for converting sas7bdat files to XPT's in a batch. Please find the attached code.
Please help me debug the code. it doesnt produce the output and no warnings in log.
/*Macro for converting SAS7bdat to xpts */
%macro xpmac(sasfloc=,ioutploc=,);
/*To get list of files in directory*/
data tdata;
length fname $300.;
rc=filename("filrf","&sasfloc");
did=dopen("filrf");
memcount=dnum(did);
if memcount>0 then do;
do i=1 to memcount;
fname=upcase(dread(did,i));
if index(trim(left(upcase(reverse(fname)))),'TDB7SAS.')=1 then output;
end;
end;
else stop;
rc=dclose(did);
run;
%let sasfcount=0;
/*Assign in macro variable for naming the sas7bdat file*/
data new;
set tdata end=last;
call symput('sasbfile'||left(_n_),trim(left(fname)));
if last then call symput('sasfcount',left(_n_));
run;
/*library for output dataset location;*/
libname libout xport "&ioutploc";
/*Do Loop for each sas7bdat file;*/
%do lindx=1 %to &sasfcount;
/*Assign file reference to the sas7bdat file*/
filename ftemp "&sasfloc\&&sasbfile&lindx";
/*Reading the first line of the sas7bdat file*/
data _null_;
length firstline $15.;
infile ftemp obs=1;
input firstline;
if index(upcase(firstline),'HEADER')>0 then call symput('lxpttype','COPY');
run;
%if &lxpttype=COPY %then %do;
libname libin "&sasfloc\&&sasbfile&lindx";
/*For converting xpt to datasets*/
proc sql noprint;
create table _tmembers as select memname, "&&sasbfile&lindx" as source length 200 from dictionary.tables where libname='LIBIN';
(select memname from dictionary.tables where libname='LIBIN');
quit;
proc copy in=libin out=libout memtype=data;
run;
%end;
%end;
%mend xpmac;
%xpmac(sasfloc=,ioutploc=)
Thank you
Bharath
... View more