LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (October 2008, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 9 Oct 2008 12:40:31 -0400
Reply-To:     Evan Davies <esdav2@WM.EDU>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Evan Davies <esdav2@WM.EDU>
Subject:      closing dataset opened in a macro

I have created a macro that puts the name of a variable into a dataset alongside a value of that variable. In the macro, I call the varname and varnum sysfunctions, which in turn call the %sysfunc open function to open the dataset so they can see the variable name and dsn id number.

Submitted as a batch job, all is well. But as I'm developing and submitting portions of the program interactively, I find that I can not re-open or re-run data steps or proc sql statement for any datasets that the macro has touched because:

ERROR: You cannot open WORK.ADDRESSC.DATA for output access with member-level control because WORK.ADDRESSC.DATA is in use by you in resource environment DMS Process.

Yes, the macro call has left the data set 'open'. The documentation says to use the CLOSE function, but I haven't been able to get the syntax right, especially where to put the 'close' statement. At the end, but inside, the macro?

The documentation also says that "If you open a data set within a DATA step, it will be closed automatically when the DATA step ends." This must not apply to macro calls within datasteps?

Much appreciation will be given to anyone who can give me the correct syntax to close my dataset so that I can open them again in the same SAS session.

The macro:

%macro pass (aval=,bval=,cval=,dsn=,anom=,studyterm=,suspend_date=,data_own=) ; aval = &aval; aval_desc = "%sysfunc(varname( %sysfunc(open(&dsn,i)) , %sysfunc(varnum(%sysfunc(open(&dsn,i)),&aval) )) )";; bval = &bval; bval_desc = "%sysfunc(varname( %sysfunc(open(&dsn,i)) , %sysfunc(varnum(%sysfunc(open(&dsn,i)),&bval) )) )"; cval = &cval; cval_desc = "%sysfunc(varname( %sysfunc(open(&dsn,i)) , %sysfunc(varnum(%sysfunc(open(&dsn,i)),&cval) )) )"; anom=&anom; studyterm=&studyterm; first_anom_date=today(); suspend_date=&suspend_date; data_own=&data_own; %mend pass;

A typical call made to the macro: (Note that PERSON is the dataset name, also being passed as parameter)

data T_person_v2; set person; *test5 - ssn out of range; if tax_id ^= '' then do; if substr(tax_id,6,4) = '0000' or substr(tax_id,1,3) < '001' or substr(tax_id,4,2) = '00' or substr(tax_id,1,3) > &highestssn then do; %pass(aval=tax_id, bval=full_name_lfmi, cval='', dsn=person, anom=5,studyterm=&study,suspend_date=.,data_own='reg') end; end; if anom > 0; run;

What I think I need:

Some form of: %let rc=%sysfunc(close(data-set-id));

Where does this go? What is the correct syntax? Do I have to issue it six times, since the open call occurs six times? And to get data-set-id, don't I have to issue another open command?


Back to: Top of message | Previous page | Main SAS-L page