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.
Hi:
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?
cynthia
Thanks cynthia .
Its a interview question asked.
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 =
,byvar =
,dupvar =
);
%if &dupvar = %then %let dupvar = &byvar;
proc sort data = &dataset
out = sorted
;
by &byvar;
run;
data dups;
set sorted;
by &byvar;
if not (first.&dupvar and last.&dupvar);
run;
%mend Find_Dups;
%Find_Dups( dataset = MyData
,byvar = EmployeeID);
Thanks a ton.
Good explanation.
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!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.