|
Dear Helen,
I'm at home now and don't have SAS at hand, but I see your filename
statement from the macro not being executed/generated by the macro. That is
the cause, so XLFILE is an unassigned file reference. And I think that is
caused by the * (asterisk) in your file name specification when calling the
macro. I'm not sure, but it could very well be that the * starts a comment
of which the FILENAME statement is part. The semicolon after the macro call
does not close the SAS comment statement, but the %LET macro statement. So,
I think you have to supply the * in a different way. Try %STR(*) or other
macro quoting functions. Or surround the whole filespec by single or double
quotes in the macro call and remove the doubled quotes in the FILENAME
statement around &dir.
I hope this helps you to solve the problem. I think this is the direction
to search in.
Regards - Jim.
On Fri, 3 Sep 2004 09:43:18 -0700, Helen <sunchunkui@HOTMAIL.COM> wrote:
>Dear SAS-l,
>
>I am trying to get the lastest Excel filename according to modified
>date under a certain directory. It works well without macro. But it
>gave me error message "No logical assign for filename " in the
>following macro. Any comments?
>
>Thanks!
>Helen
>
>1
>2 %macro GetLatestFileName(dir);
>3 filename xlfile pipe "dir ""&dir""" lrecl=200;
>4 data in;
>5 infile xlfile length=len;
>6 input char $varying200. len;
>7
>8 retain lastestname lastestdate ;
>9 date=input(substr(char,1,10),mmddyy10.);
>10 name=scan(char,4,' ');
>11 if _n_=1 then do; lastestname=name; lastestdate=date;
>end;
>12 if date>lastestdate then do;lastestname=name;
>lastestdate=date; end;
>13 call symput("fname",trim(lastestname));
>14 run;
>15 filename xlfile clear;
>16 &fname;
>17 %mend;
>18
>19 options mprint;
>20 %let test=%GetLatestFileName(c:\temp\*.xls);
>MPRINT(GETLATESTFILENAME): data in;
>MPRINT(GETLATESTFILENAME): infile xlfile length=len;
>MPRINT(GETLATESTFILENAME): input char $varying200. len;
>MPRINT(GETLATESTFILENAME): retain lastestname lastestdate ;
>MPRINT(GETLATESTFILENAME): date=input(substr(char,1,10),mmddyy10.);
>MPRINT(GETLATESTFILENAME): name=scan(char,4,' ');
>MPRINT(GETLATESTFILENAME): if _n_=1 then do;
>MPRINT(GETLATESTFILENAME): lastestname=name;
>MPRINT(GETLATESTFILENAME): lastestdate=date;
>MPRINT(GETLATESTFILENAME): end;
>MPRINT(GETLATESTFILENAME): if date>lastestdate then do;
>MPRINT(GETLATESTFILENAME): lastestname=name;
>MPRINT(GETLATESTFILENAME): lastestdate=date;
>MPRINT(GETLATESTFILENAME): end;
>MPRINT(GETLATESTFILENAME): call symput("fname",trim(lastestname));
>MPRINT(GETLATESTFILENAME): run;
>
>ERROR: No logical assign for filename XLFILE.
>ERROR: No logical assign for filename XLFILE.
>ERROR: No logical assign for filename XLFILE.
>NOTE: The SAS System stopped processing this step because of errors.
>NOTE: SAS set option OBS=0 and will continue to check statements.
>......
|