data dsn1;
input id score;
datalines;
1 22
1 55
2 55
4 .
4 44
;
run;
data dsn2;
input id $ score;
datalines;
6 55
6 .
7 12
8 44
9 66
9 14
;
run;
data con_to_numeric;
set dsn2;
id1=input(id ,best8.);
rename id1= id;
run;
data combine;
set dsn2 con_to_numeric;
run;
how to combine dataset if different datatypes in datastep and proc sql
Do it in one step:
data want;
set
dsn1 (
in=in1
rename=(id=id1)
)
dsn2
;
if in1 then id = input(id1.best.);
drop id1;
run;
But with ID's you should convert everything to character with formatting as documented for your data.
You can append data sets using the OUTER UNION CORRESPONDING statement in PROC SQL.
In work.ds2, the id column is converted from character to numeric using the input() function.
proc sql;
create table work.want as
select *
from dsn1
outer union corresponding
select input(id,1.) as id
, score
from dsn2
order by id;
quit;
Thank you for your solution
Do it in one step:
data want;
set
dsn1 (
in=in1
rename=(id=id1)
)
dsn2
;
if in1 then id = input(id1.best.);
drop id1;
run;
But with ID's you should convert everything to character with formatting as documented for your data.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.