BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
sasnewbie5
Fluorite | Level 6

I have three datasets that I need to concatenate. One was created via a one-to-one merge of datasets, the other two are just regular datasets. I wrote the code but it only outputs data from the second set. I have attached the code I have so far, as well as the two datasets (I can attach the two individual datasets that were used to create the merged dataset called Dept1).

 

Any help is greatly appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

If the log says there is 18 observations in the Employee data set, there is 18 observations in the Employee data set. Period 🙂

 

When I run this exact code

 

/***Problem #1***/
data Dept1Names;
input name $ empid $;
datalines;
NELSON 254
MITCHELL 362
PEREZ 910
CARTER 935
;
data Dept1Salaries;
input salary  id $;
datalines;
103100 254
100200 362
73500 910
88400 935
;

data Dept1;
merge Dept1Names Dept1Salaries;
keep name salary;
run;

/***Problem #2***/	
data Dept2;
input name $ salary;
datalines;
ROBERTS 74000
TURNER 89200
PHILLIPS 87000
CAMPBELL 104600
PARKER 87800
EVANS 73100
EDWARDS 72300
COLLINS 100500
;

data Dept3;
input name $ salary;
datalines;
STEWART 102600
SANCHEZ 103300
MORRIS 87200
ROGERS 70700
REED 73000
COOK 88900
;

data Employee;
	set Dept1 Dept2 Dept3;
run;

proc print data=Employee;
run;

I see this

Capture.PNG

 

 

View solution in original post

8 REPLIES 8
PeterClemmensen
Tourmaline | Level 20

Please post your code directly in your post using the little running man symbol.

sasnewbie5
Fluorite | Level 6
data Dept1Names;
input name $ empid $;
datalines;
NELSON 254
MITCHELL 362
PEREZ 910
CARTER 935
;
data Dept1Salaries;
input salary  id $;
datalines;
103100 254
100200 362
73500 910
88400 935
;

data Dept1;
merge Dept1Names Dept1Salaries;
keep name salary;
run;

/***Problem #2***/	
data Dept2;
input name $ salary;
datalines;
ROBERTS 74000
TURNER 89200
PHILLIPS 87000
CAMPBELL 104600
PARKER 87800
EVANS 73100
EDWARDS 72300
COLLINS 100500
;


data Dept3;
input name $ salary;
datalines;
STEWART 102600
SANCHEZ 103300
MORRIS 87200
ROGERS 70700
REED 73000
COOK 88900
;

data Employee;
	set Dept1 Dept2 Dept3;
run;	

The code under "Problem 1" created the first dataset via one to one merging. Then under "problem 2", I'm trying to concatenate the dataset from problem one with the other two newly created datasets.

sasnewbie5
Fluorite | Level 6

Ok so it seems that it does concatenate two of the three datasets. However, the one that I previously created does not concatenate with them. Can anyone provide any insight/solution as to why the first already-merged dataset won't concatenate?

PeterClemmensen
Tourmaline | Level 20

I do not agree. When I run this code, the employee data set contains 18 variables (4 drom Dept1, 8 from Dept2 and 6 from Dept3).

sasnewbie5
Fluorite | Level 6

Hmmm, I'm not sure why but when I run it it only shows 14. I did notice that the log says that 18 observations were created but it still only shows 14 in the output. I have absolutely no idea what's going on with this one. 

sasnewbie5
Fluorite | Level 6

I just refreshed the library and now it shows 18. Usually I don't have to do this but for some reason I had to this time. Thanks for confirming the results Draycut!

PeterClemmensen
Tourmaline | Level 20

Anytime 🙂 Glad you found your answer. Please mark the thread as accepted to help other users navigate the communities

PeterClemmensen
Tourmaline | Level 20

If the log says there is 18 observations in the Employee data set, there is 18 observations in the Employee data set. Period 🙂

 

When I run this exact code

 

/***Problem #1***/
data Dept1Names;
input name $ empid $;
datalines;
NELSON 254
MITCHELL 362
PEREZ 910
CARTER 935
;
data Dept1Salaries;
input salary  id $;
datalines;
103100 254
100200 362
73500 910
88400 935
;

data Dept1;
merge Dept1Names Dept1Salaries;
keep name salary;
run;

/***Problem #2***/	
data Dept2;
input name $ salary;
datalines;
ROBERTS 74000
TURNER 89200
PHILLIPS 87000
CAMPBELL 104600
PARKER 87800
EVANS 73100
EDWARDS 72300
COLLINS 100500
;

data Dept3;
input name $ salary;
datalines;
STEWART 102600
SANCHEZ 103300
MORRIS 87200
ROGERS 70700
REED 73000
COOK 88900
;

data Employee;
	set Dept1 Dept2 Dept3;
run;

proc print data=Employee;
run;

I see this

Capture.PNG

 

 

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 8 replies
  • 1089 views
  • 0 likes
  • 2 in conversation