- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
--------------------------
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Great, thank you! @mkeintz
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.