[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sas-l
Subject:    Re: DELETE Statement inside a DO LOOP
From:       Prashant Chegor <pchegoor () GMAIL ! COM>
Date:       2013-06-27 5:57:49
Message-ID: 201306270557.r5R5AQNb029349 () waikiki ! cc ! uga ! edu
[Download RAW message or body]

On Wed, 26 Jun 2013 01:20:16 -0400, S=?ISO-8859-1?Q?=C3=B8ren?= Lassen
<s.lassen@POST.TELE.DK> wrote:

>Prashant,
>A DELETE statement does not mean "do not output", it means "return from
>data step code without outputting". In other words, the DELETE statement
>leaves the loop (and any level of looping and linking in the data step, it
>is a bit like throwing an exception).
>
>What you probably want to do is this:
>data temp;
>  do i=1 to 10;
>    if i=2 then continue;
>    output;
>    end;
>run;
>
>- as the CONTINUE statement jumps to the next iteration of the innermost
>loop.
>
>Regards,
>Søren
>
>On Tue, 25 Jun 2013 00:23:04 -0400, Prashant Chegor <pchegoor@GMAIL.COM>
>wrote:
>
>>Hello  Gurus,
>>
>>                 Can someone please expalin as to why the following
>datastep
>>gives only one Observation as the Output ?
>>
>>Data Temp;
>>Do i=1 to 10;
>>
>>If i = 2 then delete;
>>Output;
>>End;
>>Run;
>>
>>
>>I was expecting 9 Observation to appear in the Output but i guess
>something
>>is happening here which causes it to output only one Observation.
>>
>>Is this because when i=2 in PDV , the PDV contents is deleted in
>accordance
>>with the IF statement and therefore the OUTPUT statement is not executed
>and
>>therefore the PDV contents is is not initialized to missing  and still has
>>the value of i=2 for the records i>2 and therefore all these get deleted
>>thus retaining only one observation ie i=1 in the output?

Thank You all  for the Explanation. Nice to see the Response from all of you
on this.This looked Tricky initially to me.
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic