DATA Step, Macro, Functions and more

Create macro for to cross check the uniqueness of employee id

Reply
Frequent Contributor
Posts: 89

Create macro for to cross check the uniqueness of employee id

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.

SAS Super FREQ
Posts: 8,743

Re: Create macro for to cross check the uniqueness of 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

Frequent Contributor
Posts: 89

Re: Create macro for to cross check the uniqueness of employee id

Thanks cynthia .

Its a interview question asked.

Super User
Posts: 3,110

Re: Create macro for to cross check the uniqueness of employee id

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);


Frequent Contributor
Posts: 89

Re: Create macro for to cross check the uniqueness of employee id

Thanks a ton.

Good explanation.

Ask a Question
Discussion stats
  • 4 replies
  • 312 views
  • 0 likes
  • 3 in conversation