08-04-2016 01:20 PM
I am having trouble proceeding to the next iteration of my %do loop after recognizing that a dataset I am working with is empty. The code I am working on is structured below. I don't know an easy way to recognize the data set is empty and then skip to the next iterative step. I tried using %goto method but I couldn't get it to work. Also, since my %do is outside my data step, I can't use continue; to proceede either.
%macro macro2(varC, varD);
%do i = 1 %to &snum;
08-04-2016 01:55 PM
Don't define a macro within a macro. You're asking for trouble.
How are you checking if your dataset is empty? It should be as simple as %if/%then-%do
08-04-2016 02:00 PM
One approach is to check if the data set you name has any observations you could do that with this code after the %do statement:
proc sql noprint; select nobs into setsize from dictionary.tables where libname='WORK' and memname=upcase("&S_i"); quit; %if &setsize > 0 %then %do; <code to execute when the dataset has any observations> %end;
You data step would go within the <> area. Since you are using a single level dataset name I am assuming the sets are in the WORK library. If that is not the case then put the approriate library in the comparison with Libname
You could also use an %else /%end to do something when the set is empty.
Untested for missing datasets.