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
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
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;
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
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
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.
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.