BookmarkSubscribeRSS Feed
bollibompa
Quartz | Level 8

Hi,

I hope someone can help me solve this:

I have created a macro appedning two datasets (creatd in another macro):

%macro p_loop;

    %do i=&start %to &stop;

        data P_LOOP_&i;

            set C_LOOP_&i T_LOOP_&i ;

            run;

    %end;

%mend;

%p_loop;

Let say that every generated p_loop_&i includes 10 000 rows.

p_loop_1 =10 000

p_loop_2 = 10 000

p_loop_3 = 10 000

I now want to create another loop/macro that appends the p_loops

The first will include 10 000 rows

The second will include p_loop_1 and p_loop_2 and contain 20 000 rows

The third will include p_loop_1 and p_loop_2 and p_loop_3 and contain 30 000 rows

and so on..

Thanks in advance

/Thomas

6 REPLIES 6
Kurt_Bremser
Super User

do

*initialize target dataset;

data p_loop_all;

set c_loop_1 (obs=0) t_loop_1 (obs=0);

run;

%macro p_loop;

    %do i=&start %to &stop;

          data P_LOOP_&i;

            set C_LOOP_&i T_LOOP_&i ;

            run;

            proc append data=P_LOOP_&i base=p_loop_all;

            run;

    %end;

%mend;

%p_loop;

bollibompa
Quartz | Level 8

Thanks  thats great!

It is possible to also keep the "base" each loop  (p_loop_all_&):

Like this:

p_loop_all_1  (contains 10000 rows)

p_loop_all_2  (contains 20000 rows)

p_loop_all_3  (contains 30000 rows)

/T

Kurt_Bremser
Super User

*initialize target dataset;

data p_loop_all;

set c_loop_1 (obs=0) t_loop_1 (obs=0);

run;

%macro p_loop;

    %do i=&start %to &stop;

          data P_LOOP_&i;

            set C_LOOP_&i T_LOOP_&i ;

            run;

            data p_loop_all_&i;

            set p_loop_all%eval(&i-1) p_loop_&i;

            run;

    %end;

%mend;

%p_loop;

bollibompa
Quartz | Level 8

Thanks everyone for brilliant answers!

Solved!

Thomas

Karthikeyan
Fluorite | Level 6

If I understood correctly , you again want to create three data sets out of p_loop_1 ,p_loop_2 & p_loop_3

1st ----- p_loop-1

2nd ----- p_loop_1 & p_loop_2

3rd ----- p_loop_1 , p_loop_2 & p_loop_3

%macro p_loop_apnd;

%let start = 1;

%let stop = 3;

%do i = &start %to &stop;

data

p_loop_apnd&i

;

set

%do j = &start %to &i;

  p_loop_&j

%end;

;

run;

%end;

%mend ;

%p_loop_apnd;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Hi,

Not entirely clear to me, but why not do:

data _null_;

     do i=1 to 3;

          call execute('data want'||put(i,1.)||'; set p_loop1-p_loop'||put(i,1.)||'; run;');

     end;

run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 2029 views
  • 0 likes
  • 4 in conversation