Double looping and until end of file set up

Reply
Contributor
Posts: 46

Double looping and until end of file set up

I would like to understand how to do 1 through end-of-file
dobule looping.

Here is my question,

I would like the program to do use table A for just one time and
use table B for the rest of program.

===========================================
do i=1 to 1;
use A;

TASK.................
end;

do i=2 to eof;
use B;
TASK.................
end;
end;

============================================
however, I am not very familier with how to set up with the dobule looping,
eapecially I am writing this as a macro.
so my question is,
1. what is the correct SAS language to do the set up the above pseudo program
2. how to do the 2nd loop to let it run from 2 to eof.any other definition work
   i need to do before jumping to the 2nd loop?

thank you all very much!

Valued Guide
Posts: 858

Re: Double looping and until end of file set up

It would be helpful if you gave an example of what you have followed by the result that you want.

Super User
Posts: 5,352

Re: Double looping and until end of file set up

The simplest example of double looping doesn't even require the program to add a loop.

In the simplest case, data set A contains just one observation.  To make that single observation available to every observation in data set B:

data want;

   if _n_=1 then set A;

   set B;

run;

But what if A contains multiple observations, all of which should be processed before touching data set B?  A single loop is one possibility:

data want;

   if _n_=1 then do until (end_a);

      set A end=end_a;

      * add whatever processing you want here for data set A;

   end;

   set B;

run;

Most cases that involve a double loop process the SAME data set twice, processing a subset of the records each time:

data want;

   do until (last.id);

      set A;

      by ID;

      * add some processing;

   end;

   do until (last.id);

      set A;

      by ID;

      * add some different processing that utilizes the results of the first loop;

      output;

   end;

run;

But you will need to be more specific, if you require a more specific answer than that.

Good luck.

Super User
Super User
Posts: 6,842

Re: Double looping and until end of file set up

What do you want to do?  Sounds like you just want to use a SET statement with two datasets.

data want ;

  set a b ;

run;

Valued Guide
Posts: 858

Re: Double looping and until end of file set up

I'll take a guess and say google double dow loop, I think that'll do it.

Go Pirates

Ask a Question
Discussion stats
  • 4 replies
  • 614 views
  • 1 like
  • 4 in conversation