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 (January 2004, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 29 Jan 2004 21:38:01 +0100
Reply-To:   Datametric <datametric@CLUB-INTERNET.FR>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Datametric <datametric@CLUB-INTERNET.FR>
Subject:   RE : RE : a question of End SAS macro
Comments:   To: Jack Hamilton <JackHamilton@FIRSTHEALTH.COM>
In-Reply-To:   <s018fa44.010@SLCM02.firsthealth.com>
Content-Type:   text/plain; charset="iso-8859-1"

If you read the Miranda's question, you will see that she wants to stop her macro if the data is empty : "My question is : How could I stop my macro running here If the data set is 0 obs and the further data steps won't run?"

I'm agree with you, my first test on &syserr is not the most important but the test with 'nobs' implies to skip the others statements if it's equal to 0, so I add the %err_step label to do this cleanly.

About the test, Don suggests something interesting. but in my last mail, I pointed out (in friendly way) that I answered to Miranda how to go out on error, not only how to detect an empty data. Miranda is free to use any proposition to test the data, but she wanted to stop the macro too.

No ? Miraaaaanda ???? ;-)

Stéphane.

-----Message d'origine----- De : SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] De la part de Jack Hamilton Envoyé : jeudi 29 janvier 2004 20:19 À : SAS-L@LISTSERV.UGA.EDU Objet : Re: RE : a question of End SAS macro

An answer which is sometimes incorrect and often inefficient is still an answer, yes. But in this case, Don's answer is clearly better - it always works, and it's always going to be fairly efficient compaed to other methods of reading the same input.

-- JackHamilton@FirstHealth.com Manager, Technical Development Metrics Department, First Health West Sacramento, California USA

>>> "SUBSCRIBE SAS-L Stephane" <datametric@CLUB-INTERNET.FR> 01/29/2004 >>> 8:41 AM >>> Hi,

you're right. But I answered to the question : How stop the macro statements while an error occurs in a datastep and if the nobs eq 0. Not only how to know if the data is empty.

Stéphane.

----Message d'origine---- >Date: Wed, 28 Jan 2004 20:17:17 -0500 >De: Don Henderson <donaldjhenderson@HOTMAIL.COM> >Sujet: Re: RE : a question of End SAS macro >A: SAS-L@LISTSERV.UGA.EDU > >If the issue is detecting whether the data set is empty, then the >following should work and does not depend on dictionary tables, works >for view and data sets, etc. > >%let anyobs = 0; >data _null_; > set my-data-set-name(obs=1); > call symput('anyobs','1'); >run; > >The macro variable anyobs defaults to 0 (i.e., No obs) and is reset to >1 (i.e., has obs) by the call symput if there is at least one >observation. > >I would also like to point out that this is a case where the original >question was much simpler than the question answered by the list. Yes, >determining how many observations a data set has will allow one to >determine if it has any obs. But you don't need to count them, to know >if there are any. > >Regards, >-don h > >----- Original Message ----- >From: "Jack Hamilton" <JackHamilton@FIRSTHEALTH.COM> >Newsgroups: bit.listserv.sas-l >To: <SAS-L@LISTSERV.UGA.EDU> >Sent: Wednesday, January 28, 2004 7:44 PM >Subject: Re: RE : a question of End SAS macro > > >> Just remember that the dictionary table entries won't always be >> accurate. >> >> >> >> -- >> JackHamilton@FirstHealth.com >> Manager, Technical Development >> Metrics Department, First Health >> West Sacramento, California USA >> >> >>> "Choate, Paul@DDS" <pchoate@DDS.CA.GOV> 01/28/2004 4:24 PM >>> >> Stéphane- >> >> You jogged my memory of another method to quickly get the number of >> obs posted by Jim Groeneveld a little while back... >> >> DATA _NULL_; >> IF 0 THEN SET dataset NOBS=NrOfObs; >> CALL SYMPUT ('NrOfObs', PUT(NrOfObs, BEST12.)); >> STOP; >> RUN; >> >> It essentially does exactly what your >> >> %let v_op_table = %sysfunc(open(a&name.&site.)); >> %let v_obs_table = %sysfunc(attrn(&v_op_table, nobs)); >> %let v_cl_table =%sysfunc(close(&v_op_table)); >> >> does: opens the tables, reads the NOBS attribute, and closes the >> table. >> >> Both are much faster than my method of using proc sql noprint to >> extract >the >> nobs value from dictionary.tables, especially if there are a large >> number >of >> tables. >> >> Regards.... >> >> Paul Choate >> DDS Data Extraction >> (916) 654-2160 >> >> -----Original Message----- >> From: Datametric [mailto:datametric@CLUB-INTERNET.FR] >> Sent: Wednesday, January 28, 2004 3:30 PM >> To: SAS-L@LISTSERV.UGA.EDU >> Subject: RE : a question of End SAS macro >> >> Hi, >> >> You should try this : >> >> %macro check(name,site); >> >> libname lib "..... "; >> >> data a&name.&site.; >> set lib.&name. (where=(site=&site.)); >> run; >> >> /* use this for each datastep. this is a generic message */ %if >> &syserr > 0 %then %let v_err= error on "&syslast"; %if &syserr > 0 >> %then %goto err_step; >> >> >> /* for the nobs */ >> %let v_op_table = %sysfunc(open(a&name.&site.)); >> %let v_obs_table = %sysfunc(attrn(&v_op_table, nobs)); >> %let v_cl_table =%sysfunc(close(&v_op_table)); >> >> %if &v_obs_table = 0 %then %let v_err = data "a&name.&site." is >> empty; %if &v_obs_table = 0 %then %goto err_step; >> >> /* continue */ >> there are more data steps from here.. >> .. >> .. >> .. >> .. >> .. >> .. >> >> /* if it's right, you have to jump de err_step label used to generic >> error message */ %put check is OK; >> %goto end; >> >> /* label inidcates error, and could contains a global variable used >> for return code (RC) if %check is called by an another macro */ >> >> %err_step: >> %let rc=4; >> %put &v_err; >> %put the macro &sysmacroname is stopped; >> >> %end: >> >> %mend check; >> >> You should use the abort statement but it's more violent. >> >> Stéphane. >> >> >> -----Message d'origine----- >> De : SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] De la part de >miranda >> Envoyé : mercredi 28 janvier 2004 21:59 >> À : SAS-L@LISTSERV.UGA.EDU >> Objet : a question of End SAS macro >> >> >> Hi, >> I have a SAS macro like this: >> >> %macro Check(name,site); >> >> libname lib "..... "; >> >> data a&name.&site.; >> set lib.&name.; >> if site=&site.; >> run; >> >> My question is : How could I stop my macro running here If the data >> set is >0 >> obs and the further data steps won't run? >> >> >> There are more data steps from here.. >> .. >> .. >> .. >> .. >> .. >> .. >> %mend Check; >> >> >> Thanks. >> > >


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