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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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