Hello~
I'm quite new to the SAS platform.
I'm trying to make a one table with multiple table using do loop.
There are two factors increasing until 10.
Here is the example.
Thank you for your help.
Sinserely.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
DATA OSUMF;
SET OSUM1F_1 OSUM1F_2 OSUM1F_3 OSUM1F_4 OSUM1F_5 OSUM1F_6 OSUM1F_7 OSUM1F_8 OSUM1F_9 OSUM1F_10
OSUM2F_2 OSUM2F_3 OSUM2F_4 OSUM2F_5 OSUM2F_6 OSUM2F_7 OSUM2F_8 OSUM2F_9 OSUM2F_10
OSUM3F_3 OSUM3F_4 OSUM3F_5 OSUM3F_6 OSUM3F_7 OSUM3F_8 OSUM3F_9 OSUM3F_10
OSUM4F_4 OSUM4F_5 OSUM4F_6 OSUM4F_7 OSUM4F_8 OSUM4F_9 OSUM4F_10
OSUM5F_5 OSUM5F_6 OSUM5F_7 OSUM5F_8 OSUM5F_9 OSUM5F_10
OSUM6F_6 OSUM6F_7 OSUM6F_8 OSUM6F_9 OSUM6F_10
OSUM7F_7 OSUM7F_8 OSUM7F_9 OSUM7F_10
OSUM8F_8 OSUM8F_9 OSUM8F_10
OSUM9F_9 OSUM9F_10
OSUM10F_10
;
RUN;
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
If using wildcards is not feasible, use a macro loop:
%macro combine;
data osumf;
set
%do i =1 %to 10;
%do j = &i. %to 10;
osum&i.f_&j.
%end;
%end;
; /* this ends the SET */
run;
%mend;
%combine
Why not just use a wildcard suffix?
data all;
set OSUM: ;
run;
Are there other datasets that start with those characters that you DONT want to include? If se why not? Where did they come from.
There is an intermediate solution, as opposed to a DO loop (which would require macro coding, or programming for a CALL EXECUTE statement:
data osumf;
set osum1f_1-osum1f_10 osum2f_2-osum2f_10 osum3f_3-osum3f_10
osum4f_4-osum4f_10 osum5f_5-osum5f_10 osum6f_6-osum6f_10
osum7f_7-osum7f_10 osum8f_8-osum8f_10 osum9f_9-osum9f_10
osum10f_10;
Here is a semi-macro approach:
filename setstmt temp ;
data _null_;
file setstmt;
length txt $200;
do x=1 to 10;
txt=catx(' ',txt,cats('osum',x,'F_',x,'-osum',x,'F_10'));
end;
put 'set ' txt ';' ;
run;
data _null_;
%include setstmt /source2;
run;
If using wildcards is not feasible, use a macro loop:
%macro combine;
data osumf;
set
%do i =1 %to 10;
%do j = &i. %to 10;
osum&i.f_&j.
%end;
%end;
; /* this ends the SET */
run;
%mend;
%combine
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.