DATA Step, Macro, Functions and more

recognising empty datasets

Reply
Contributor
Posts: 47

recognising empty datasets

Hi All,

The way I've setup my program I extract subsets of data (as tables) from a large dataset. Sometimes these tables are completely empty. Its become a problem since I output these tables onto a pdf and I can sometimes have a number of empty tables.

My question is, is there a way to recognise that the entire table is empty so I could skip outputing this table and go to the next?

Thanks,
Sachin
Valued Guide
Posts: 634

Re: recognising empty datasets

Posted in reply to SachinRuk
Do you need to know if a table currently has 0 obs? 0 variables? or do you need to know that a given logical expression will produce no observations for a given data set?
Contributor
Posts: 47

Re: recognising empty datasets

Posted in reply to SachinRuk
well its more that all the values are 'missing'. So to me its zero observations but thats not how SAS perceives it.

Mind you that proc gplot doesnt attempt to give me an empty graph, simply doesnt plot altogether (which is what I want).

Thanks,
Sachin Message was edited by: SachinRuk
Occasional Contributor
Posts: 12

Re: recognising empty datasets

Posted in reply to SachinRuk
there is a macro in the SAS Autocall library called obsnvars which returns the number of observations and number of variables as values of macro variables that you can then test and take action based on the values. snippet from some code where it is in use here

%obsnvars(CST.&&tablename&i);
%if &nobs GT 0
%then %do;
proc sql noprint;
create table max_date as
select
"&&tablename&i" length=50 as table_name
,max(extracteddate) as max_extracteddate
from CST.&&tablename&i
;
quit;
data all_table_dates;
set all_table_dates
max_date
;
run;
%end;
%end;
Valued Guide
Posts: 2,177

Re: recognising empty datasets

Posted in reply to SachinRuk
SachinRuk

While creating your subsets you might be able to collect what you seek more easily than after.
Are you using SQL or a data step or just a where clause?
Optimal solution depends on context.

HTH
peterC
Ask a Question
Discussion stats
  • 4 replies
  • 201 views
  • 0 likes
  • 4 in conversation