%IF NOBS > 0 AND %SYSFUNC(EXIST(TEST)) = 1 %THEN %DO;
This statement doesn't work as you think it will. You probably think NOBS is some number that the macro processor understands, but it is not. NOBS inside this %IF statement is a text string of four letters, the first letter is N, the second letter is O, and so on; and so NOBS is not a number. Macros evaluate text in a certain way, and the text string NOBS is always greater than 0, so code 1 always results.
Perhaps you mean
%IF &NOBS > 0 THEN ...
so if &NOBS contains a number then you could test if that number is > 0, but nowhere have you defined what the value of &NOBS is, so as shown, this wouldn't work either.
You didn't state your objective — is it trying to execute one set of code if data set TEST exists and has more than 0 observations, and execute other code if either TEST doesn't exist or has zero observations?
--
Paige Miller