Desktop productivity for business analysts and programmers

Combine Tables Help

Reply
Occasional Contributor
Posts: 5

Combine Tables Help

Hi all,

Sorry in advance if this is a silly question. But how do I combine 2 columns from two different SAS files? I tried query building, but query builder created a SAS file with two seperate columns and I want these two columns combine into one column instead. Am I using the wrong tool or is there another way to join.

Thanks in advance.

Alex

Frequent Contributor
Posts: 128

Re: Combine Tables Help

I think it would make it easier for us to help you out if you provided some example data in the two data sets you want to combine, and then a brief example of the output you're looking to achieve.  Dummy data can be used, just so we understand the structure of the two data sets and the desired output you are wanting.  Thanks!

Grand Advisor
Posts: 10,211

Re: Combine Tables Help

Provide some examples of the 2 input data sets and what you want the output to look like. There are several ways to interpret "combine 2 columns" and details will help. Also let us know, if there is possible confusion, if a variable that looks numeric is actually a character variable.

Esteemed Advisor
Posts: 5,198

Re: Combine Tables Help

If you are using enterprise guide query builder, you need to define a calculated column, where you need to specify an expression how you wish to combine the column values.

Data never sleeps
Occasional Contributor
Posts: 5

Re: Combine Tables Help

So, it is actually really simple. I have two SAS data files.

Capture.PNG

I want to combined then to one that looks like this.

Capture1.PNG

File 1 has a bunch of text, file 2 has a bunch of text. I want them in one column. However, I am currently getting them in two columns when running query builder with outer joint function.

Capture3.PNG

Thanks for your help.

Occasional Contributor RRM
Occasional Contributor
Posts: 5

Re: Combine Tables Help

You can use proc append. just make sure that the column has the same name in each dataset.

proc append base=file1 data=file2; run;

Grand Advisor
Posts: 17,356

Re: Combine Tables Help

Tasks>Data>Append Table

Super User
Super User
Posts: 6,347

Re: Combine Tables Help

So to combine two tables without matching the rows you can use the SET statement in SAS.

data want;

  set a b ;

run;

Or if you have some ID variables that the two datasets are sorted on you can use a BY statement to insure that the generated table is also sorted.

data want;

  set a b ;

  by id ;

run;

Occasional Contributor
Posts: 7

Re: Combine Tables Help

You could try an insert into statement:

proc sql;

insert into table_1

(column1, column2, column3)

select column1, column2, column3

from table_2;

run;

If there is a specific subset from table_2, you can use a where statement after the from statement such as

from table_2

where column2="something";

Ask a Question
Discussion stats
  • 8 replies
  • 536 views
  • 0 likes
  • 8 in conversation