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

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
Calcite | Level 5
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
Calcite | Level 5
I would want to stack the data sets

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 983 views
  • 1 like
  • 3 in conversation