Date: Wed, 10 Jul 2002 20:07:31 -0400
Reply-To: "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Richard A. DeVenezia" <radevenz@IX.NETCOM.COM>
Organization: MindSpring Enterprises
Subject: Re: Close datasets
Content-Type: text/plain;
"Clemens van Brunschot" <c.vanbrunschotNO@JUNKchello.nl> wrote in message
news:3d2c1364$0$32503$7a0f4ed3@energis-news-env...
> Hello Richard,
>
> The problem is that during execution of my macros (not AF) due to wrong
> input sometimes SAS gets into an error while a dataset was opened. And it
> will leave the dataset open so that the macro cannot be run again. When I
> try, SAS will tell me that the dataset cannot be opened since it is
already
> open (don't have the correct phrasing at hand now).
>
snip
Ah, now things become more clear.
A dataset opened with %SYSFUNC(OPEN(...)) could indeed be left open.
The problem is that there is no way (that I know) to know how many are
open.
Dataset ID's are handled 'doled' out by SAS, in sequential order. When a
data set is close it's ID (handle) is then available to the next use of
OPEN().
E.g. use open() 20 times, close id 10, and use open() again. It will return
dsid 10, not 21.
Thus, there is no way to statelessly know the handles of the open datasets
(you _should_ be tracking them so you can close them).
You would have to implement a closeall macro that would make a stab at
closing open datasets.
%macro closeall (N=100);
%local i rc;
%do i = 1 %to &N;
%let rc = %sysfunc (CLOSE(&i));
%end;
%mend;
Assuming you don't have more than 100 open's active (you can have multiple
opens against one dataset) at the time of the error, then the macro will
close what was left open.
--
Richard A. DeVenezia
http://www.devenezia.com/downloads/sas/macros/#sas2xls
Use Perl to create an Excel file containing one worksheet per SAS dataset