I have a program that imports a large number of spreadsheets into data sets. It runs fine the first time. The second time I run it, I get errors because the output data set is being used. Proc datasets also cannot delete the data sets. The code is like the following (inside a macro loop that generates different &seriesid values.
I'm using EG 8.5 (8.5.0.203) (32-bit).
filename _TSss temp;
proc http method="get"
url="&tableURL"
out=_TSss;
run;
proc import datafile=_TSss out=_TSss_&seriesid dbms=xlsx replace; range=&seriesid._data; getnames=no; run;
Found the problem (I think). Nothing to do with proc import. Later in the program I run this macro which I use to rename the first variable in the file. I guess I need to put a close statement in there somewhere?
%macro FirstVName(data);
%* returns the name of the first variable in a file;
%let dsid = %sysfunc(open(&data,i));
%sysfunc(varname(&dsid,1))
%mend FirstVName;
The OPEN function will indeed create a file lock. The CLOSE function will remove it. It is always a good idea to ensure that you CLOSE OPENed files explicitly in your SAS application and not rely on just closing your SAS session which will also release these file locks.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.