BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
BrahmanandaRao
Lapis Lazuli | Level 10
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

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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.

View solution in original post

4 REPLIES 4
Astounding
PROC Star
Your sample program would work except for two small errors.

First, the logic for con_to_numeric creates two variables both named ID. That's not allowed. To fix that, add before the RENAME statement:

drop id;

Second, your last SET statement reads the wrong data sets. It should say:

set dsn1 con_to_numeric;
ChanceTGardener
SAS Employee

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;
BrahmanandaRao
Lapis Lazuli | Level 10

Hi @ChanceTGardener 

Thank you for your solution

Kurt_Bremser
Super User

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.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

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
  • 863 views
  • 0 likes
  • 4 in conversation