Date: Tue, 11 May 2010 05:29:08 -0400
Reply-To: Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Gerhard Hellriegel <gerhard.hellriegel@T-ONLINE.DE>
Subject: Re: Alternative for "goto" in do loop
It is simply a construct which is strictly forbidden for structured
programming. It is comes from early assembler days, where you had no loop-
constructs like UNTIL, WHILE, DO i=1 TO... It was necessary to simulate
that constructs with branches and GOTO's. In high level languages that
constructs are available and let you program in structured way, so
programs become more readable. It is sometimes very hard to read and
understand a assembler program, with structured programs that is quite
easy.
You have already some good advices how to rewrite your SAS program.
Gerhard
On Mon, 10 May 2010 23:12:33 -0400, Sid N <nsid31@GMAIL.COM> wrote:
>Hi,
>
>I am trying to understand the "goto" sequences in the second data step
>below:
>
>data range1;
>informat start end date9.;
>format start end date9.;
>input start end;
>start_m = month(start);
>end_m = month(end);
>start_y = year(start);
>end_y = year(end);
>cards;
>01JAN1975 01JAN1977
>01AUG1979 01JUL1980
>01MAR2008 01JAN2010
>01DEC2000 01SEP2002
>01FEB2010 01NOV2011
>;
>run;
>
>data range2;
>set range1;
>do y = start_y to end_y by 1;
>if y < 1980 then goto skip3;
>if y > 2009 then goto skip2;
> do m = 1 to 12 by 1;
> if (start_m > m and y = start_y) then goto skip1;
> if (y = end_y and end_m < m) then goto skip2;
> output;
> skip1:;
> end;
>skip3:;
>end;
>skip2:;
>run;
>
>
>Can someone please help me understand the "goto" sequences in the
above "do
>loop"? I have heard that using "goto" sequences may not be an efficient
way
>to code in SAS. Please suggest an alternative to output what the above
code
>is accomplishing using different programming logic.
>
>Thank you for your time.
>
>Sid
|