|
5#

楼主 |
发表于 2011-5-19 04:51:17
|
只看该作者
Re: 如何根据特定要求删掉一个dataset?
Another one:
[code:2k3cnk7a]/* Create a macro that returns: */
/* 1 - if a specified variable is present in a given dataset, or */
/* 0 - otherwise */
%macro existsVariable(lib = work, ds =, var =);
%local dsid check rc;
%if &lib. = %then %let lib = work;
%let dsid = %sysfunc(open(&lib..&ds.));
%let check = %sysfunc(varnum(&dsid., &var.));
%let rc = %sysfunc(close(&dsid.));
%if &check. = 0 %then %do;
0
%end; %else %do;
1
%end;
%mend existsVariable;
/* Create a test dataset that has two variables, var1 and var2. */
data test;
var1 = 1; var2 = 2; output;
run;
/* Delete the dataset test if it does not contain variable var3. */
proc datasets lib = work nolist;
%sysfunc(ifc(%existsVariable(ds = test, var = var3) = 0, delete test, ));
quit;
[/code:2k3cnk7a] |
|