08-24-2014 01:45 PM
There is a list of employee ID and every month a new employee is added. Write a Macro program to cross check the uniqueness of the employee ID.
08-24-2014 02:01 PM
You do not need a macro program to do this. Simply create a temporary file for the new month and then use PROC FREQ with nlevels. Any EmpID with nlevel=2 is a duplicate. Or use PROC SORT with the DUPOUT option. Or define an index for Employee ID in the main/master file to have the UNIQUE property and you will not be able to add duplicate employee IDs to the master file. This sounds like a homework problem. What code have you tried? Even if you do ultimately want a macro program, you have to start with a working SAS program before you "macro-ize" it. So, show your work. What does the input data look like for the "master" file? What does the data look like for the monthly add? What is the working program to add the new observation(s) to the master file?
08-24-2014 04:09 PM
As a general rule a macro is only useful if it is to be repeated multiple times in your SAS jobs.
Therefore it might be a good idea to have general "check for duplicates" macro that could be applied to any dataset with a key variable and not just employee ID. Here is an example and this is one way of answering your interviewer
%macro Find_Dups ( dataset =
%if &dupvar = %then %let dupvar = &byvar;
proc sort data = &dataset
out = sorted
if not (first.&dupvar and last.&dupvar);
%Find_Dups( dataset = MyData
,byvar = EmployeeID);