| Date: | Wed, 28 Jan 2004 11:44:24 +0530 |
| Reply-To: | "Yerramsetty, Naveen Kumar (Cognizant)"
<ynaveen@CHN.COGNIZANT.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | "Yerramsetty, Naveen Kumar (Cognizant)"
<ynaveen@CHN.COGNIZANT.COM> |
| Subject: | Re: how-to stop datasteps if nobs=0 in macro |
|
| Content-Type: | multipart/mixed;
|
|---|
HI Arto,
I have sample macro code which tests for DS and if it exists assigns the no of obs and no of vars to global variables.
You can use these global variables to find out the number of obs.
Hope this helps you.
%macro obsnvars(ds);
%GLOBAL dset nvars nobs;
%let dset=&ds;
%let dsid = %sysfunc(open(&dset));
%if &dsid %then
%do;
%let nobs =%sysfunc(attrn(&dsid,NOBS));
%let nvars=%sysfunc(attrn(&dsid,NVARS));
%let rc = %sysfunc(close(&dsid));
%end;
%else
%put Open for data set &dset failed - %sysfunc(sysmsg());
%mend obsnvars;
Thanks,
Naveen
-----Original Message-----
From: Arto Raiskio [mailto:arto-nospam@RAISKIO.COM]
Sent: Sunday, January 25, 2004 5:01 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: how-to stop datasteps if nobs=0 in macro
I have some macrocode which looks like the following sample and the question
is how to best stop the code so that the proc printto is not executed and
Zero byte reports files written (empty report files)
code runs on windows, sas is version 9
%macro something;
data....(a datastep)
proc ..(some procstep)
proc printto file= (this would write output to a file if records exist)
%mend;
normally, on a mainframe job, one could use something like
data _null_;set a nobs=nobs; if nobs=0 then abort abend 0001;run;
what might be the easiest way to stop the macro just before the proc printto
?
This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information.
If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.
Any unauthorised review, use, disclosure, dissemination, forwarding, printing or copying of this email or any action taken in reliance on this e-mail is strictly
prohibited and may be unlawful.
Visit us at http://www.cognizant.com
|