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 2012, week 5)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 30 Jan 2012 02:45:04 -0500
Reply-To:     Søren Lassen <s.lassen@POST.TELE.DK>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Søren Lassen <s.lassen@POST.TELE.DK>
Subject:      Re: non-SAS-killing ABORT for interactive mode, is there one?
Comments: To: Eugene Bolotin <YBolotin@SCHOOLS.NYC.GOV>
Content-Type: text/plain; charset=ISO-8859-1

Yevgeniy, I made a small mistake in my orginal post. The macro variable that I had meant to use was SYSCC, not SYSRC. SYSCC works the way I described, while SYSRC reports errors with the X statement.

Sorry about that.

Regards, Søren

On Thu, 26 Jan 2012 10:19:57 -0500, Bolotin Yevgeniy <YBolotin@SCHOOLS.NYC.GOV> wrote:

>This is pretty cool, will have to play with it > >Thanks! > > > >-----Original Message----- >From: Søren Lassen [mailto:s.lassen@POST.TELE.DK] >Sent: Thursday, January 26, 2012 5:53 AM >To: SAS-L@LISTSERV.UGA.EDU; Bolotin Yevgeniy >Subject: Re: non-SAS-killing ABORT for interactive mode, is there one? > >Yevgeniy, >Here is a solution that uses old-style macros (mixed with "new"-style): >%macro errchk; > %if &sysrc %then %do; > macro run run cancel% > macro sql sql noexec% > macro kill% > %end; > %else %do; > macro run run% > macro sql sql% > macro kill kill% > %end; >%mend; > >%let sysrc=0; /* no errors yet */ >%errchk; > >data _z; a = 1; output; a = 2; output; run; > >%let sysrc=1; /* Simulate an error */ >%errchk; > >Proc sql; > create table _z as select * from _z, _z; >quit; > >proc datasets lib=work kill nolist mt=data; >run; > > >What it does: it checks the automatic variable SYSRC. SYSRC is set to the >maximum of the automatic variable RC (I think it is that one) and SYSRC >after each step. However, you can reset it to 0 in your program. > >If SYSRC is not 0, it makes SAS do an old-style macro substitution of >the word RUN with RUN CANCEL, of SQL with SQL NOEXEC and of KILL with >nothing. If SYSRC is 0, it resets the tokens to their normal values. > >This means that after the (simulated) error, the SQL procedure statements >are not executed, only syntax checked. And likewise are datasteps >and most other procedures that excute after RUN; an exception is PROC >DATASETS, which deletes tables (and/or views,catalogs) regardless, >when the KILL options is used - therefore the KILL token is nulled when >there is an error. > >Just remember to use RUN in PROC DATASETS and not QUIT. And generally, >use RUN after all your datasteps/procedures except SQL. > >If you need to stop execution based on data values, you can do something >like: >data _null_; > set _z; > if a>1 then do; > call symput('sysrc','1'); > stop; > end; >run; > >%errorchk; > >Regards, >Søren > >On Wed, 25 Jan 2012 15:58:09 -0500, Bolotin Yevgeniy ><YBolotin@SCHOOLS.NYC.GOV> wrote: > >>Joe and _null_: >> >>Abort abend/return does exactly what I want, but with one exception: it >>ALSO kills SAS (as in, the application closes). I want to retain my SAS >>session (and formats, macro variables/sasmacr, WORK library, etc) >> >>option OBS = 0 kinda works, but not the way I need (it goes through the >>rest of the code anyway, nuking *everything* in its path) >> >> >> >>so here's a goal: given the following (ultra-simplified) code >> >> data _z; a = 1; output; a = 2; output; run; >> * CODE TO STOP EXECUTION HERE; >> Proc sql; create table _z as select * from _z, _z; quit; >> >>I want to run the whole thing, and end up with the dataset _z with two >>observations (and not zero) >> >>This is obviously a silly example, but I may end up using this break >>logic in the middle of a large set of macro calls, where datasets are >>updated left and right (some of these files are 15gb - so during >>different stages of processing I may merge it to other files maybe a >>dozen times each - making a differently-named version each time is not >>feasible) >> >> >> >> >> >> >> >>-----Original Message----- >>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of >>Data _null_; >>Sent: Wednesday, January 25, 2012 2:40 PM >>To: SAS-L@LISTSERV.UGA.EDU >>Subject: Re: non-SAS-killing ABORT for interactive mode, is there one? >> >>Seems like in DMS that ERRORABEND may work toward this objective too. >> >>On 1/25/12, Joe Matise <snoopy369@gmail.com> wrote: >>> You need to set obs=0 also. This is what batch mode does when it >>encounters >>> an error - sets SYNTAXCHECK and obs=0. >>> >>> -Joe >>> >>> On Wed, Jan 25, 2012 at 1:04 PM, Bolotin Yevgeniy >>> <YBolotin@schools.nyc.gov>wrote: >>> >>>> Syntaxcheck doesn't seem to be doing what I want it to be doing >>>> (DMSSYNCHK is the interactive version) - it only affects the dataset >>>> with the error in it >>>> >>>> Both valid datasteps and proc sql execute just fine in the below >>sample >>>> >>>> >>>> >>>> option DMSSYNCHK SYNTAXCHECK; >>>> >>>> data _null_; >>>> set non_existent_dataset; >>>> run; >>>> >>>> data _null_; >>>> kjhlksafhkdfhlah; /* syntax error */ >>>> run; >>>> >>>> data _z; >>>> a = 1; >>>> run; >>>> >>>> data _z2; >>>> set _z; >>>> run; >>>> >>>> proc sql; >>>> create table _z3 as >>>> select * from _z; >>>> quit; >>>> >>>> >>>> >>>> >>>> -----Original Message----- >>>> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of >>>> Data _null_; >>>> Sent: Wednesday, January 25, 2012 1:16 PM >>>> To: SAS-L@LISTSERV.UGA.EDU >>>> Subject: Re: non-SAS-killing ABORT for interactive mode, is there >>one? >>>> >>>> You could put SAS into syntax check, obs=0 mode based on some >>>> condition. You will need to check the exact options that need to be >>>> set. >>>> >>>> On 1/25/12, Bolotin Yevgeniy <YBolotin@schools.nyc.gov> wrote: >>>> > This has probably been asked before but I can't seem to find what I >>>> > want... >>>> > >>>> > Is there a simple command I can write in code to force SAS to abort >>>> the >>>> > currently submitted code (i.e. equivalent to Cancel Submitted >>>> Statements >>>> > from the Break menu), that DOESN'T actually shut down SAS in the >>>> process >>>> > like ABORT does? >>>> > Even if the abort cannot be made conditional, this can work wonders >>>> for >>>> > debugging (i.e. insert as a breakpoint) >>>> > >>>> > >>>> > I've seem some interesting approaches to doing this with macros >>>> > injecting comment delimiters (i.e. /* ) but this is both way too >>>> > complicated for what I'm doing and requires way too much work to >>>> > implement on existing projects >>>> > >>>> > >>>> > >>>> > Using SAS 9.2 on WinXP (32 bit) >>>> > >>>> >>>


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