What is the right selection for this problem and why? Thanks:
Given the SAS data set WORK.EMP_NAME:
Name EmpID
---- -----
Jill 1864
Jack 2121
Joan 4698
John 5463
Given the SAS data set WORK.EMP_DEPT:
EmpID Department
----- ----------
2121 Accounting
3567 Finance
4698 Marketing
5463 Accounting
The following program is submitted:
data WORK.ALL;
merge WORK.EMP_NAME(in=Emp_N)
WORK.EMP_DEPT(in=Emp_D);
by Empid;
if (Emp_N and not Emp_D) or (Emp_D and not Emp_N);
run;
How many observations are in data set WORK.ALL after submitting the program? A. 1 B. 2 C. 3 D. 5
Answer will be B.2 2 observations with 3 variables already, so new dataset ALL will have observations what are not neither in EMP_NAME or EMP_DEPT column EmpID . Library actually is WORK for all.
This statement does show that to merge only observations that are not common/present in EmpID when merging. Emp_N is from first dataset and Emp_D is from second dataset.
by Empid;
if (Emp_N and not Emp_D) or (Emp_D and not Emp_N);
Hope it helps with the details bellow:
title "stackoverflow merge EMP_DEPT";
data work.EMP_NAME;
input Name $ EmpID;
datalines;
Jill 1864
Jack 2121
Joan 4698
John 5463
;
run;
proc print data = work.EMP_NAME;
run;
title "stackoverflow merge EMP_DEPT";
data work.EMP_DEPT;
input EmpID Department $ ;
datalines;
2121 Accounting
3567 Finance
4698 Marketing
5463 Accounting
;
run;
proc print data = work.EMP_DEPT;
run;
*merge;
data WORK.ALL;
merge WORK.EMP_NAME(in=Emp_N)
WORK.EMP_DEPT(in=Emp_D);
by Empid;
if (Emp_N and not Emp_D) or (Emp_D and not Emp_N);
run;
proc contents data=work.ALL;
run;
proc print data = work.ALL;
run;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.