Help using Base SAS procedures

Help with a macro-appending data

Reply
Contributor
Posts: 73

Help with a macro-appending data

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

Super User
Posts: 7,832

Re: Help with a macro-appending data

Posted in reply to bollibompa

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;

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 73

Re: Help with a macro-appending data

Posted in reply to KurtBremser

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

Super User
Posts: 7,832

Re: Help with a macro-appending data

Posted in reply to bollibompa

*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;

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 73

Re: Help with a macro-appending data

Posted in reply to KurtBremser

Thanks everyone for brilliant answers!

Solved!

Thomas

Contributor
Posts: 37

Re: Help with a macro-appending data

Posted in reply to bollibompa

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;

Super User
Super User
Posts: 7,977

Re: Help with a macro-appending data

Posted in reply to bollibompa

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;

Ask a Question
Discussion stats
  • 6 replies
  • 267 views
  • 0 likes
  • 4 in conversation