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
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;
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
*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;
Thanks everyone for brilliant answers!
Solved!
Thomas
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;
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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.