BookmarkSubscribeRSS Feed
willy0625
Calcite | Level 5

So I am trying to combine the two tables given below by using PROC SQL.

DATA Math;

    INPUT name $ mark;

    DATALINES;

A 94

B 92

;

DATA Phy;

    INPUT name $ mark;

    DATALINES;

B 92

C 81

;

This is the output I want:

name mark

  A      94

  B      92

  C      81

But I keep getting

name mark

  A      94

  B      92

  .       81

Any suggestions?

Many thanks

4 REPLIES 4
MichelleHomes
Meteorite | Level 14

You need to use the coalesce function on your name variables so that it will return the nonmissing value. Look for this in the sql help...

Cheers,

Michelle

//Contact me to learn how Metacoda software can help keep your SAS platform secure - https://www.metacoda.com
Oleg_L
Obsidian | Level 7

Try this code.


proc sql noprint;
create table new as select coalescec(a.name,b.name) as name length=1, coalesce(a.mark,b.mark) as mark
from math as a full join phy as b on a.name=b.name;
quit;

Howles
Quartz | Level 8

Since MATH and PHY have the same structure, just use a simple UNION.

create table want as

select * from math

union

select * from phy

;

willy0625 wrote:

So I am trying to combine the two tables given below by using PROC SQL.

DATA Math;

    INPUT name $ mark;

    DATALINES;

A 94

B 92

;

DATA Phy;

    INPUT name $ mark;

    DATALINES;

B 92

C 81

;

This is the output I want:

name mark

  A      94

  B      92

  C      81

But I keep getting

name mark

  A      94

  B      92

  .       81

Any suggestions?

Many thanks

Ksharp
Super User

Add a little into Howels's code.

Because Howels's union is column matched,

and need to add corresponding to make sure to name matched.

create table want as

select * from math

union corresponding

select * from phy

;

Ksharp

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1751 views
  • 8 likes
  • 5 in conversation