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

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!

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.

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
  • 4 replies
  • 758 views
  • 8 likes
  • 5 in conversation