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
SAS Super FREQ

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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