Solved
Contributor
Posts: 33

# Creating a new variable with information from 2 tables

Hello,
I would like to add a column to Table 1, the "des" column.

If table1.cat = table2.id then table1.des = table2.des

Table1:

 Cat Name 1 zer 4 tez 3 dgr 1 ffz 1 fzgtjt 2 pojn 2 fj 3 kfi 3 ndonz

Table 2

 id des 1 com 2 the 3 action 4 sade

And the table that I receive

 Cat Name des 1 zer com 4 tez sade 3 dgr action 1 ffz com 1 fzgtjt com 2 pojn the 2 fj the 3 kfi action 3 ndonz action

Accepted Solutions
Solution
‎02-24-2018 09:48 AM
PROC Star
Posts: 1,209

## Re: Creating a new variable with information from 2 tables

Do like this

``````data table1;
input Cat Name \$10.;
datalines;
1 zer
4 tez
3 dgr
1 ffz
1 fzgtjt
2 pojn
2 fj
3 kfi
3 ndonz
;

data table2;
input id	des \$10.;
datalines;
1 com
2 the
3 action
;

proc sql;
create table want as
select table1.*
,table2.des
from table1, table2
where table1.cat=table2.id;
quit;

proc print data=want;run;``````

All Replies
Solution
‎02-24-2018 09:48 AM
PROC Star
Posts: 1,209

## Re: Creating a new variable with information from 2 tables

Do like this

``````data table1;
input Cat Name \$10.;
datalines;
1 zer
4 tez
3 dgr
1 ffz
1 fzgtjt
2 pojn
2 fj
3 kfi
3 ndonz
;

data table2;
input id	des \$10.;
datalines;
1 com
2 the
3 action
;

proc sql;
create table want as
select table1.*
,table2.des
from table1, table2
where table1.cat=table2.id;
quit;

proc print data=want;run;``````
Contributor
Posts: 33

## Re: Creating a new variable with information from 2 tables

Great thank you very much!
☑ This topic is solved.