0

I wrote a SAS macro kind of like this...

%macro (myname=,myurl=);
    filename myfile URL "&myurl";
    data &myname;
    infile myfile dlm=',';
    input field1 field2;
    run;
%mend;

It works once, but Whenever I run it again, I get log messages saying:

ERROR: At least one file associated with fileref MYFILE is still in use.
ERROR: Error in FILENAME statement.

I also get these messages if I attempt to filename myfile CLEAR or filename myfile NULL

Also, if I run it with several URLs, only the first dataset gets created and the others are exact copies of it.

I have no access to the SAS configuration files. I have to solve this without any sort of administrative rights.

Thanks.

bokov
  • 3,444
  • 2
  • 31
  • 49
  • I tried creating dynamic names for the fileref and I get `ERROR: Invalid logical name.` `ERROR: Error in the filename statement`. Does this mean that SAS doesn't permit a variable to be used as a fileref? – bokov Dec 02 '12 at 00:47
  • Apparently if the name you give your fileref is longer than 8 characters it gets truncated, and that for some reason causes SAS to look in the SYS32 folder for a physical file by that name instead of looking in the URL you specify. Using short, dynamically generated fileref names allows me to use my macro with multiple URLs. But, this is a kludgy, ugly solution that litters the environment with filerefs that don't go away and I really hope someone knows of a cleaner way to do this. – bokov Dec 02 '12 at 02:19
  • 1
    I don't have a problem with that code (well, fixed for minor syntax issues but certainly not your problem). It reruns fine (using random websites). Does it work for you if you use a few URLs like google.com or sas.com? Is it something specific to the files/server/connection you're using? Is the data step in the macro functioning as you would expect the first time, at least? – Joe Dec 02 '12 at 02:44
  • My workaround with dynamically named filerefs seems to be working, but if I can reproduce the original problem, I will post an update. – bokov Dec 02 '12 at 20:09

1 Answers1

0

I'm thinking you could add a FILENAME CLEAR at the end of your macro:

%macro (myname=,myurl=);
    filename myfile URL "&myurl";
    data &myname;
    infile myfile dlm=',';
    input field1 field2;
    run;

    filename myfile clear;
%mend;
DavB
  • 1,676
  • 2
  • 14
  • 16
  • `ERROR: At least one file associated with fileref MYFILE is still in use. ERROR: Error in FILENAME statement.` – bokov Dec 05 '12 at 07:07
  • Is MYFILE listed in SASAUTOS? See http://support.sas.com/kb/31/540.html. You can check your SASAUTOS option using %PUT %SYSFUNC(GETOPTION(SASAUTOS)); This will output it to the log. – DavB Dec 05 '12 at 08:30