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
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!
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.
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.
So, it is actually really simple. I have two SAS data files.
I want to combined then to one that looks like this.
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.
Thanks for your 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;
Tasks>Data>Append Table
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;
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";
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.