Help using Base SAS procedures

Add a check point to the entire procedure

Reply
Regular Contributor
Posts: 154

Add a check point to the entire procedure

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!

Trusted Advisor
Posts: 1,337

Re: Add a check point to the entire procedure

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;
Regular Contributor
Posts: 154

Re: Add a check point to the entire procedure

Great, thank you! @mkeintz

PROC Star
Posts: 2,363

Re: Add a check point to the entire procedure

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

 

 

 

 

 

Ask a Question
Discussion stats
  • 3 replies
  • 162 views
  • 1 like
  • 3 in conversation