Hi,
I have a question on setting a check point within the SAS code. This check point could decide if later procedures will run or stop.
The code has 10 input tables: Table1, Table2, ..., Table10.
Later procedures will run if Table1 through Table10 they all have observations (not empty). Later procedure will stop if any one of Table1 through Table10 is empty.
I know the following code could check whether the table is empty or not for 1 table:
Proc Sql noprint;
Select * from Table1;
Quit;
put *&sqlobs*;
if &sqlobs > 0
then do;
...
else do;
end;
How could I apply similar procedure to 10 tables? Is there any simple way?
Thank you!
You can use the DICTIONARY feature of proc sql, specifically dictionary.tables. Lets say you want to examine all datasets whose name begins with 'X' in the work library:
proc sql noprint;
select
case when min(nobs)>0 then 'CONTINUE' else 'STOP' end
into :status
from dictionary.tables
where libname='WORK' and memname like 'X%';
quit;
%put &=status;
%if &status=CONTINUE %then %do;
...
...
%end;
Great, thank you! @mkeintz
With this method, you have to encase the whole program in a macro for %if statements to be accepted, and you end up with 10 nested tests (unless you use %goto).
That's a sad limitation of SAS's that one has to resort to such kludges.
See here.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.