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

Hello, I need to combine about ten tables all with different names (example: work.weight, work.diagnosis, work.dose) into one table with a variable that specifies their original table name.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Are you stacking the data or merging the data (adding variables)?

 

data want;
set weight diagnosis dose indsname=src;
source = src;
run;

 Merge (one option)

data want;
merge weight (in=t1) diagnosis (in=t2) dose (in=t3);
by subjid;
src=catx('|', t1, t2, t3);
run;

You likely need to provide more details to get an answer that's more specific to what you need.

View solution in original post

7 REPLIES 7
PaigeMiller
Diamond | Level 26

@jmmedina252 wrote:

Hello, I need to combine about ten tables all with different names (example: work.weight, work.diagnosis, work.dose) into one table with a variable that specifies their original table name.

 


Could you define "combine"?? Do you want these tables to be combined horizontally, side by side? Or do you want these tables to be combined vertically, one on top of another? Or do you want something else?

--
Paige Miller
Reeza
Super User
Then try the first set of code I included.
jmmedina252
Fluorite | Level 6
is there anyway to exclude the libname without saving the data sets to work? instead of source=data.dose I would want source=dose
Reeza
Super User
Use SCAN() to parse just the second portion.

source =scan(src, 2, ".");
Reeza
Super User

Are you stacking the data or merging the data (adding variables)?

 

data want;
set weight diagnosis dose indsname=src;
source = src;
run;

 Merge (one option)

data want;
merge weight (in=t1) diagnosis (in=t2) dose (in=t3);
by subjid;
src=catx('|', t1, t2, t3);
run;

You likely need to provide more details to get an answer that's more specific to what you need.

jmmedina252
Fluorite | Level 6
I would want to stack the data sets

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 7 replies
  • 1319 views
  • 1 like
  • 3 in conversation