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 |
Thanks for your help
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
4 sade
;
proc sql;
create table want as
select table1.*
,table2.des
from table1, table2
where table1.cat=table2.id;
quit;
proc print data=want;run;
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
4 sade
;
proc sql;
create table want as
select table1.*
,table2.des
from table1, table2
where table1.cat=table2.id;
quit;
proc print data=want;run;
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.
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.