BookmarkSubscribeRSS Feed
venkatnaveen
Obsidian | Level 7

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.

4 REPLIES 4
Cynthia_sas
Diamond | Level 26

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

venkatnaveen
Obsidian | Level 7

Thanks cynthia .

Its a interview question asked.

SASKiwi
PROC Star

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


venkatnaveen
Obsidian | Level 7

Thanks a ton.

Good explanation.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1942 views
  • 0 likes
  • 3 in conversation