BookmarkSubscribeRSS Feed
yoyong
Obsidian | Level 7

Hi.

 

I have two data sets which look like these:

 

Data set 1:

 

ID_No               Type     

A1                     1            

A1                     1              

B2                     3 

C3                     4

C3                     4 

C3                     4

D4                     4

 

Data set 2:

 

ID_No              Branch

A1                       1

B2                       2

C3                       3

D4                       4

 

The two data sets have other variables but I don't want them.

But I would like to my data set to look like this:

 

ID_No                Branch              Type

A1                       1                           1

B2                       2                           3

C3                       3                           4

D4                       4                           4

 

 

 How do I program this?

 

Thank you very much for your help!

 

 

 

1 REPLY 1
EEng
Obsidian | Level 7

You can do this.

data ds1 (keep=ID_No Type);
	 input ID_No $ Type;
	 datalines;
A1 1
A1 1
B2 3
C3 4
C3 4
C3 4
D4 4
;
run;
proc print data=ds1;
run;
data ds2 (keep=ID_No Branch);
	 input ID_No $ Branch;
	 datalines;
A1 1
B2 2
C3 3
D4 4
;
run;
proc print data=ds2;
run;
proc sort nodupkey data=ds1;
	 by ID_No Type;
run;
proc sort data=ds2;
	 by ID_No;
run;
data outdata;
	 merge ds1 ds2;
	 by ID_No;
run;
proc print data=outdata;
run;

Your output will look like this

 

Obs ID_No Type
1A11
2A11
3B23
4C34
5C34
6C34
7D44
Obs ID_No Branch
1A11
2B22
3C33
4D44
Obs ID_No Type Branch
1A111
2B232
3C343
4D444

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 16. 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
  • 1 reply
  • 672 views
  • 0 likes
  • 2 in conversation