BookmarkSubscribeRSS Feed
Crubal
Quartz | Level 8

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!

3 REPLIES 3
mkeintz
PROC Star

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;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Crubal
Quartz | Level 8

Great, thank you! @mkeintz

ChrisNZ
Tourmaline | Level 20

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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 835 views
  • 1 like
  • 3 in conversation