BookmarkSubscribeRSS Feed
Alex_Ji
Calcite | Level 5

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

8 REPLIES 8
dcruik
Lapis Lazuli | Level 10

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!

ballardw
Super User

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.

LinusH
Tourmaline | Level 20

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
Alex_Ji
Calcite | Level 5

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.

RRM
Calcite | Level 5 RRM
Calcite | Level 5

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;

Reeza
Super User

Tasks>Data>Append Table

Tom
Super User Tom
Super User

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;

jsasusr
Fluorite | Level 6

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";

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 8 replies
  • 1522 views
  • 0 likes
  • 8 in conversation