SAS中文论坛

标题: 请教open() function [打印本页]

作者: shiyiming    时间: 2011-9-16 02:07
标题: 请教open() function
data b;
input x1 y;
cards;
1 20
2 50
;
run;
%macro aaa;
%let dsid=%sysfunc(open(b));
%if %sysfunc(varnum(&dsid.,x))^=0 %then %do;
data c;set b;
xy=x;
run;
%end;
%else %do;
data c;set b;
xy=y;
run;
%end;
%mend;
%aaa

如例所示,运行之后,便无法删除data b. log提示data b在使用中,这是怎么回事?
如果是open的原因,请问,在使用open的前提下,我该如何关闭,或如何去除这个情形(不能自由的建立或删除一个dataset)?
thanks a lot!
作者: shiyiming    时间: 2011-9-16 03:51
标题: Re: 请教open() function
you have to close the dataset somewhere before the %mend;

        %let dsid=sysfunc(close(&dsid));
作者: shiyiming    时间: 2011-9-16 22:04
标题: Re: 请教open() function
I tried, but failed for %let dsid=%sysfunc(close(&dsid));  .
even I tried  %let dsid=%sysfunc(close(b));, but still wrong;
could anyone give me a suggestion, thanks a lot.
作者: shiyiming    时间: 2011-9-17 09:18
标题: Re: 请教open() function
Close your SAS, re-start it. open funcion and colse funcion must be used in pair.
作者: shiyiming    时间: 2011-9-18 03:03
标题: Re: 请教open() function
yes, I tried again according what you suggested, cloase SAS and reopen it(repeat it hundreds times). then, run the code besides the line :
data b;
input x1 y;
cards;
1 20
2 50
;
run;
%macro aaa;
%let dsid=%sysfunc(open(b));
%if %sysfunc(varnum(&dsid.,x))^=0 %then %do;
data c;set b;
xy=x;
run;
%end;
%else %do;
data c;set b;
xy=y;
run;
%end;

%let dsid=%sysfunc(close(&dsid));
/*
%let dsid=sysfunc(close(&dsid)); or
%let dsid=%sysfunc(close(&dsid)); or
%let rc=%sysfunc(close(&dsid));
*/

%mend;
%aaa

however, nothing changed, and the problem still there.(BTW, what is your SAS? 9.1 or 9.2? Mine is 9.1.)
can anyone help? Thanks.
作者: shiyiming    时间: 2011-9-18 04:01
标题: Re: 请教open() function
i restarted my PC&SAS and run the code, everything looks normal now, thanks a lot!!!
作者: shiyiming    时间: 2011-9-19 23:34
标题: Re: 请教open() function
其实跟你用察看器打开数据集道理一样的,你要关上才行。
作者: shiyiming    时间: 2011-9-21 23:00
标题: Re: 请教open() function
the correct way is to close the dataset before your next step to open it.
%macro aaa;
%let dsid=%sysfunc(open(b));
%if %sysfunc(varnum(&dsid.,x))^=0 %then %do;
%let dsid=%sysfunc(close(&dsid));
data c;set b;
xy=x;
run;
%end;
%else %do;
%let dsid=%sysfunc(close(&dsid));
data c;set b;
xy=y;
run;
%end;

%mend;
%aaa




欢迎光临 SAS中文论坛 (http://mysas.net/forum/) Powered by Discuz! X3.2