DATA Step, Macro, Functions and more


Occasional Contributor
Posts: 8


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)
by Empid;
if (Emp_N and not Emp_D) or (Emp_D and not Emp_N);



can somebody plz how i m getting 2 observations in work.all data set , how this if condition is selecting the data .

Frequent Contributor
Posts: 118

Re: Merging

The if (Emp_N and not Emp_D) gets the rows in the EMP_NAME data set that are not in the EMP_DEPT data set.  There's one: Jill.


The if (Emp_D and not Emp_N) gets the rows in the EMP_DEPT data set that are not in the EMP_NAME data set.  There's one:  The empID 3567 in Finance.


The OR means that you want the rows that are in one data set but not the other, so you have 2 observations in the ALL data set.  

Super User
Posts: 10,238

Re: Merging

@SuzanneDorinski already told you what happens.

I just want to add some food for thought: a simpler form of the condition would be

if Emp_N ne Emp_D;
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation