Date: Mon, 2 Jul 2001 14:02:52 -0700
Reply-To: Pete Lund <pete.lund@NWCSR.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Pete Lund <pete.lund@NWCSR.COM>
Subject: Re: DO - END
In-Reply-To: <3B40D81C.6CB3DE4@admin4.hsc.uth.tmc.edu>
Content-Type: text/plain; charset="us-ascii"
Hi Mia-
The innermost END will go with the innermost DO, so the END on line 14
goes with the DO on line 11. There are two statements after your line
numbering ends. If we assume that these are 15 and 16 - the END on line 15
goes with the DO on line 9 (and the ELSE is related to that DO...END pair.
This is a good example of the importance of using a good indenting scheme
that will allow you to see the relationships of the DO and END pairs more
clearly. There's no one "right" way, but I would code your example as:
DATA FINAL;
SET MERGED;
BY TRID;
RETAIN TOT F L OBSNUM;
FORMAT TOT COMMA13.2;
IF FIRST.TRID THEN
DO;
TOT =0;
F=_N_;
END;
TOT=TOT + AMT;
IF LAST.TRID AND ABS(TOT) GE .01 THEN
DO;
L =_N_;
DO OBSNUM= F TO L;
SET MERGED POINT=OBSNUM;
OUTPUT;
END;
END;
ELSE DELETE;
RUN;
This is just one of many schemes, but the DOs and the ENDs line up and
make it a little easier to make sure that you've got it right.
*** A BIG NEW FEATURE IN V8.2 ***
One more tip that's helpful in this situation - new in V8.2 is the ability
to find DO...END pairs in the enhanced editor. Just place the cursor
anywhere inside a DO...END (usually right after the DO or right before the
END if you're looking for the match) and press ALT-[ (square bracket).
Hitting this key combination will toggle you back and forth between the DO
and the END. Similarly, CTRL-] will toggle between beginning and ending
parentheses, which can be handy with multiple nested functions.
FYI - the documentation says ALT-[ for DO...END and CTRL-] for
parenthesis. I've found that either bracket (right of left) works with
either.
----------------------------------------------------------------------------
---
Pete Lund
Northwest Crime and Social Research
313-D Fifth Ave SE
Olympia, WA 98501
(360) 528-8970 - voice
(360) 280-4892 - cell
(360) 570-7533 - fax
pete.lund@nwcsr.com
www.nwcsr.com
----------------------------------------------------------------------------
---
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU]On Behalf Of mto
Sent: Monday, July 02, 2001 1:23 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: DO - END
Would you please explain the statement below for me.
I understand from 1 - 9, but from 10 - 14, I don't know. The END on
line 14 is for the DO on line 9 or line 11? If it's for line 9, then
why the DO on line 11 doesn't have the END.
Thanks very much.
Mia
1. DATA FINAL;
2. SET MERGED;
3. BY TRID;
4. RETAIN TOT F L OBSNUM;
5. FORMAT TOT COMMA13.2;
6. IF FIRST.TRID THEN DO;
7. TOT =0; F=_N_; END;
8. TOT=TOT + AMT;
9. IF LAST.TRID AND ABS(TOT) GE .01 THEN DO;
10. L =_N_;
11. DO OBSNUM= F TO L;
12. SET MERGED POINT=OBSNUM;
13. OUTPUT;
14. END;
END;
ELSE DELETE;