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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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