LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (February 2008, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 26 Feb 2008 15:18:32 +0000
Reply-To:     toby dunn <tobydunn@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         toby dunn <tobydunn@HOTMAIL.COM>
Subject:      Re: empty data set warning in macros
Comments: To: Lenka Benková <benkova.lenka@gmail.com>
In-Reply-To:  <714bae880802260413u646b9d2dtaba4b4032658b905@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Here is a more general macro for getting a tables attribute(s) :

%Macro GetTableAttr( Lib = Work , Mem = , Attr = ) ; /******************************************************/ /** Macro Name : GetTableAttr **/ /** **/ /** Purpose : Returns The Specified Attribute For **/ /** A Data Set **/ /** **/ /** Parameters : Lib ~ Library Name Where The Data **/ /** Referenced By Mem Is Stored **/ /** **/ /** Mem ~ Name Of The Data Set That You **/ /** Want The Attribute From **/ /** **/ /** Attr ~ The Attribute You Wish To **/ /** Have Returned **/ /** For More Information On **/ /** Acceptable Values Please **/ /** ReadMe Doc For This Macro **/ /******************************************************/ /** Created By : Toby Dunn **/ /** Date Created : August 28, 2007 **/ /******************************************************/ %Local DSID Value Close ;

%If ( %Sysfunc( Exist( &Lib..&Mem ) ) Eq 0 ) %Then %Do ; %Put ; %Put ; %Put ERROR: The Data Set [&Lib..&Mem] Does Not Exist!!! ; %Put ERROR: Please Specify a Valid SAS Data Set Name ; %Put ; %Put ; %Return ; %End ;

%If ( %SysFunc( IndexW( CHARSET DATAREP ENCRYPT ENGINE LABEL LIB MEM MODE MTYPE SORTEDBY SORTLVL SORTSEQ TYPE ANY ALTERPW ANOBS ARAND ARWU AUDIT AUDIT_BEFORE AUDIT_DATA AUDIT_ERROR CRDTE GENMAX GENNEXT ICONST INDEX ISINDEX ISSUBSET LRECL LRID MODTE NDEL NLOBS NLOBSF NOBS NVARS PW RADIX READPW TAPE WHSTMT WRITEPW , %UpCase( &ATTR ) ) ) = 0 ) %Then %Do ;

%Put ; %Put ; %Put ERROR: [&Attr] Is Not A Valid Value For Parameter Attr!!! ; %Put ERROR: Please Specify One Of The Following Valid Values: ; %Put ERROR: CHARSET, DATAREP, ENCRYPT, ENGINE, LABEL, ; %Put ERROR: LIB, MEM, MODE, MTYPE, SORTEDBY, SORTLVL, ; %Put ERROR: SORTSEQ, TYPE, ANY, ALTERPW, ANOBS, ARAND, ; %Put ERROR: ARWU, AUDIT, AUDIT_BEFORE, AUDIT_DATA, ; %Put ERROR: AUDIT_ERROR, CRDTE, GENMAX, GENNEXT, ICONST, ; %Put ERROR: INDEX, ISINDEX, ISSUBSET, LRECL, LRID, ; %Put ERROR: MODTE, NDEL, NLOBS, NLOBSF, NOBS, NVARS, PW, ; %Put ERROR: RADIX, READPW, TAPE, WHSTMT, Or WRITEPW. ; %Put ; %Put ; %Return ;

%End ;

%If ( %SysFunc( IndexW( CHARSET DATAREP ENCRYPT ENGINE LABEL LIB MEM MODE MTYPE SORTEDBY SORTLVL SORTSEQ TYPE , %UpCase( &ATTR ) ) )> 0 ) %Then %Do ; %Let TblType = AttrC ; %End ;

%Else %If ( %SysFunc( IndexW( ANY ALTERPW ANOBS ARAND ARWU AUDIT AUDIT_BEFORE AUDIT_DATA AUDIT_ERROR CRDTE GENMAX GENNEXT ICONST INDEX ISINDEX ISSUBSET LRECL LRID MODTE NDEL NLOBS NLOBSF NOBS NVARS PW RADIX READPW TAPE WHSTMT WRITEPW , %UpCase( &ATTR ) ) )> 0 ) %Then %Do ; %Let TblType = AttrN ; %End ;

%Let DSID = %SysFunc( Open( &Lib..&Mem , I ) ) ;

%If ( &DSID = 0 ) %Then %Do ; %Put ; %Put ; %Put ERROR: Error Trying To Open Data Set ( %UpCase(&Lib..&Mem) ). ; %Put ERROR: %SysFunc( SysMsg( ) ). ; %Put ; %Put ; %Return ; %End ;

%Let Value = %SysFunc( &TblType( &DSID , &Attr ) ) ;

%Let Close = %SysFunc( Close( &DSID ) ) ;

%If ( &Close Ne 0 ) %Then %Do ; %Put ; %Put ; %Put ERROR: Error Trying To Close Data Set ( %UpCase(&Lib..&Mem) ). ; %Put ERROR: %SysFunc( SysMsg( ) ). ; %Put ; %Put ; %Return ; %End ;

&Value

%Mend GetTableAttr ;

Toby Dunn

"Don't bail. The best gold is at the bottom of barrels of crap." Randy Pausch

"Be prepared. Luck is where preparation meets opportunity." Randy Pausch

> Date: Tue, 26 Feb 2008 12:13:51 +0000 > From: benkova.lenka@GMAIL.COM > Subject: Re: empty data set warning in macros > To: SAS-L@LISTSERV.UGA.EDU > > Hi Stefan, > > see below, one option is to use ATTRN function, which returns numeric > attribute of specified dataset and NOBS as argument of the function. > > Lenka > > > data a; > set sashelp.class; > run; > > > %macro check_dataset (data); > > %let dsid=%sysfunc(open(&data)); > %let nrobs=%sysfunc(attrn(&dsid,nobs)); > %let dsid=%sysfunc(close(&dsid)); > > %if &nrobs=0 %then > %put WARNING: Dataset &data is empty; > %else %put NOTE: Dataset &data consists of &nrobs of observations; > > %mend; > > %check_dataset(a) > > data a; > set a; > delete; > run; > > %check_dataset(a) > > > > 2008/2/26, Stefan Pohl : >> >> Dear sas-group, >> >> within a macro I produce data sets which can be empty. I want to give out >> a >> message if that happens. >> How can I do this? >> >> Best regards, >> >> Stefan. >>

_________________________________________________________________ Connect and share in new ways with Windows Live. http://www.windowslive.com/share.html?ocid=TXT_TAGHM_Wave2_sharelife_012008


Back to: Top of message | Previous page | Main SAS-L page