- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 01-21-2008 07:06 AM
(35408 views)
Hi,
I'm looking for a simple solution to check is table empty or not.
Thanks
I'm looking for a simple solution to check is table empty or not.
Thanks
8 REPLIES 8
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I have a solution! I think this is the best one 🙂
data _null_;
call symput('obscnt',0);
set work.out;
call symput('obscnt',_n_);
stop;
run;
%If &obscnt=0 %then %do;
%put 'There are no records in a dataset.';
%end;
data _null_;
call symput('obscnt',0);
set work.out;
call symput('obscnt',_n_);
stop;
run;
%If &obscnt=0 %then %do;
%put 'There are no records in a dataset.';
%end;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here's an alternate solution:
proc sql;
select "# of Obs in WORK.OUT: ", nobs
from dictionary.tables
where libname='WORK'
and memname = 'OUT';
quit;
proc sql;
select "# of Obs in WORK.OUT: ", nobs
from dictionary.tables
where libname='WORK'
and memname = 'OUT';
quit;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
That's cool, but I don't like to be depended of this "dictionary"... Ofcourse, it's up to you... 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why don't you like to depend upon the "dictionary" tables? Unless you are using where clause in a proc or data step, the information provided by the dictionary tables is as good as SAS is.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Some people seem to have the impression that querying the Dictionary views is a slow process. In all cases I have seen, this is a result of poorly constructed SQL code and a SAS session that includes foreign (Sql server, Oracle, DB2 etc) libraries.
A well constructed SQL query such as that shown should have no performance issues.
A well constructed SQL query such as that shown should have no performance issues.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If people don't like querying dictionary tables (and I don't understand why not) you can always use the following code:
%LET dsid=%SYSFUNC(OPEN(work.dataset));
%LET nobs=%SYSFUNC(ATTRN(&dsid.,NOBS));
%LET rc=%SYSFUNC(CLOSE(&dsid.));
The number of observations is then held in a macro variable [NOBS].
%IF &Nobs. EQ 0 %THEN %DO; .... %END; etc. etc. Message was edited by: LawrenceHW
%LET dsid=%SYSFUNC(OPEN(work.dataset));
%LET nobs=%SYSFUNC(ATTRN(&dsid.,NOBS));
%LET rc=%SYSFUNC(CLOSE(&dsid.));
The number of observations is then held in a macro variable [NOBS].
%IF &Nobs. EQ 0 %THEN %DO; .... %END; etc. etc. Message was edited by: LawrenceHW
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
This is an elegant solution and one that I use a lot.
Just one warning that any %IF logic cannot be in open code -- but must be in a SAS Macro program.
cynthia
Just one warning that any %IF logic cannot be in open code -- but must be in a SAS Macro program.
cynthia
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Am try outed this but it shows as "There are no records in a dataset" also when the data set contain observation