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.
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
Please post your code directly in your post using the little running man symbol.
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.
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?
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).
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.
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!
Anytime 🙂 Glad you found your answer. Please mark the thread as accepted to help other users navigate the communities
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
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.