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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 929 views
  • 0 likes
  • 2 in conversation