BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
D_ANALYST
Fluorite | Level 6

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;

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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

View solution in original post

6 REPLIES 6
Tom
Super User Tom
Super User

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.

 

D_ANALYST
Fluorite | Level 6
I didn't know about wildcard suffix.
It can be one of the solution.
I also want to know in case there are other datasets that start with characters that I don't want to include.
In case when there OSUM1F_1 ~ OSUM25F_25.
And I just want to use from OSUM1F_1 to OSUM10F_10
Then I can't use wildcard suffix.
What can I do for that case??

D_ANALYST
Fluorite | Level 6
For example, there are two data table I want to make, OSUMC and OSUMD.
OSUMC makes with OSUM1C_1, OSUM1C_2, ... , OSUM10C_10
and OSUMD makes with OSUM1D_1, OSUM1D_2, ... , OSUM10D_10
In this case, it's hard to use wildcard suffix.
Both starts with "OSUM"
then what should I do?
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
DATA OSUMC;
SET OSUM1C_1 OSUM1C_2 OSUM1C_3 OSUM1C_4 OSUM1C_5 OSUM1C_6 OSUM1C_7 OSUM1C_8 OSUM1C_9 OSUM1C_10
OSUM2C_2 OSUM2C_3 OSUM2C_4 OSUM2C_5 OSUM2C_6 OSUM2C_7 OSUM2C_8 OSUM2C_9 OSUM2C_10
OSUM3C_3 OSUM3C_4 OSUM3C_5 OSUM3C_6 OSUM3C_7 OSUM3C_8 OSUM3C_9 OSUM3C_10
OSUM4C_4 OSUM4C_5 OSUM4C_6 OSUM4C_7 OSUM4C_8 OSUM4C_9 OSUM4C_10
OSUM5C_5 OSUM5C_6 OSUM5C_7 OSUM5C_8 OSUM5C_9 OSUM5C_10
OSUM6C_6 OSUM6C_7 OSUM6C_8 OSUM6C_9 OSUM6C_10
OSUM7C_7 OSUM7C_8 OSUM7C_9 OSUM7C_10
OSUM8C_8 OSUM8C_9 OSUM8C_10
OSUM9C_9 OSUM9C_10
OSUM10C_10
;
RUN;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
DATA OSUMD;
SET OSUM1D_1 OSUM1D_2 OSUM1D_3 OSUM1D_4 OSUM1D_5 OSUM1D_6 OSUM1D_7 OSUM1D_8 OSUM1D_9 OSUM1D_10
OSUM2D_2 OSUM2D_3 OSUM2D_4 OSUM2D_5 OSUM2D_6 OSUM2D_7 OSUM2D_8 OSUM2D_9 OSUM2D_10
OSUM3D_3 OSUM3D_4 OSUM3D_5 OSUM3D_6 OSUM3D_7 OSUM3D_8 OSUM3D_9 OSUM3D_10
OSUM4D_4 OSUM4D_5 OSUM4D_6 OSUM4D_7 OSUM4D_8 OSUM4D_9 OSUM4D_10
OSUM5D_5 OSUM5D_6 OSUM5D_7 OSUM5D_8 OSUM5D_9 OSUM5D_10
OSUM6D_6 OSUM6D_7 OSUM6D_8 OSUM6D_9 OSUM6D_10
OSUM7D_7 OSUM7D_8 OSUM7D_9 OSUM7D_10
OSUM8D_8 OSUM8D_9 OSUM8D_10
OSUM9D_9 OSUM9D_10
OSUM10D_10
;
RUN;
---------------------------------------------------------------------------------------------------------------------------------------------------------------------

mkeintz
PROC Star

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;

 

 

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Kurt_Bremser
Super User

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
D_ANALYST
Fluorite | Level 6
Thank you. It work!!!

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 6 replies
  • 2053 views
  • 6 likes
  • 4 in conversation