how to find same values in multiple rows

Reply
New Contributor
Posts: 3

how to find same values in multiple rows

I have created IDs based on birth date, gender, and residential location in SAS.

I want to flag any same codes in muliple rows by goup (ID). But i don't know how to code in SAS.

Here's my dataset.

data A;

Input ID Code1 Code2 Code3 Code4;

datalines;

     123   7581    74401    7421     .

     123   74345   7581     75161   7503

     125   7532     .            .            .

     125   7505     75672    75531   .

     125   7532     7505     .             .;

run;

Thanks,       

Trusted Advisor
Posts: 1,228

Re: how to find same values in multiple rows

Hi,

Try this to identify codes appearing in multiple rows.

data A;
Input ID Code1 Code2 Code3 Code4;
datalines;
123   7581    74401    7421     .
123   74345   7581     75161   7503
125   7532     .       .        .
125   7505     75672    75531   .
125   7532     7505     .       .
;

data b (keep= id code var);
set a;
array cod{*} Code1 Code2 Code3 Code4;
do i=1 to dim(cod);
var=vname(cod{i});
code=cod{i};
output;
end;
run;

proc sql;
select id,code from b
group by id,code
having count(code)>1;
quit;

New Contributor
Posts: 3

Re: how to find same values in multiple rows

This is very helpful. Thank you so much.

Ask a Question
Discussion stats
  • 2 replies
  • 188 views
  • 0 likes
  • 2 in conversation