Hello, I am new at using macros. I was given a macro to convert XPT files to a SAS dataset. Here is the code. %macro drive(dir,ext,out);
%let filrf=mydir;
/* Assigns the fileref of mydir to the directory and opens the directory */
%let rc=%sysfunc(filename(filrf,&dir));
%let did=%sysfunc(dopen(&filrf));
/* Returns the number of members in the directory */
%let memcnt=%sysfunc(dnum(&did));
/* Loops through entire directory */
%do i = 1 %to &memcnt;
/* Returns the extension from each file */
%let name=%qscan(%qsysfunc(dread(&did,&i)),-1,.);
/* Checks to see if file contains an extension */
%if %qupcase(%qsysfunc(dread(&did,&i))) ne %qupcase(&ext) %then %do;
/* Checks to see if the extension matches the parameter value */
/* If condition is true, submit PROC COPY statement */
%if (%superq(ext) ne and %qupcase(&name) = %qupcase(&ext)) or
(%superq(ext) = and %superq(name) ne) %then %do;
libname old xport "&dir.\%qsysfunc(dread(&did,&i))";
libname new "&out";
proc copy in=old out=new;
run;
%end;
%end;
%end;
/* Close the directory */
%let rc=%sysfunc(dclose(&did));
/* END MACRO */
%mend drive; When I run the following code %drive('\appdata\sasusers\JLANG\NHANES data', 'XPT', '\appdata\sasusers\JLANG\NHANES data\DATA') I receive the following error. ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: &memcnt ERROR: The %TO value of the %DO I loop is invalid. ERROR: The macro DRIVE will stop executing. The name of the file that Im trying to convert is DEMO_F.XPT Please let me know what im doing wrong here! Thanks for your help 🙂
... View more