data a1 ;
var1='abc' ;
var2='def' ;
var3='ghi' ;
var4='abc' ;
var5='xyz' ;
var6='def' ;
run;
I have above dataset. how to remove duplicate values column wise in arrays.
output come should come like see below example
var1=abc var2='def' var3='ghi' var4=' ' var5='xyz' var6=' '
var4 and var6 we have to assign missing values because there values already in var1 and var2.
I have tried below code. Kindly help me out.
code:
data a1 ;
var1='abc' ;
var2='def' ;
var3='ghi' ;
var4='abc' ;
var5='xyz' ;
var6='def' ;
run;
data a2 ;
set a1 ;
array apple(6) $ var1-var6 ;
do i=1 to 5;
do j=2 to 6 ;
if apple(i) ne ' ' and apple(j) ne ' ' then do ;
if (apple(i) ne ' ' and apple(j) ne ' ') and apple(i)=apple(j) then apple(i)=' ' ;
end;
end;
end;
run;
data a2 ;
set a1 ;
array apple(6) $ var1-var6 ;
do i=1 to 5;
do j=i+1 to 6 ;
if apple(i) ne ' ' and apple(j) ne ' ' then do ;
if apple(i)=apple(j) then apple(i)=' ' ;
end;
end;
end;
run;
Please, from now on, post your code in a code box, as I have done, by clicking on the "running man" icon and then pasting your code into the box.
Also, do yourself a favor and indent your code as shown above.
Depending on the number of observation i would tend to transpose the data and use proc sort to remove the duplicates.
proc transpose data=a1 out=transposed;
var var:;
run;
proc sort data=transposed out=nodups nodupkey;
by col1;
run;
For anyone who doesn't have the restriction of doing it in arrays (which I think would be almost everyone), I think @andreas_lds has the correct (and easiest) answer.
data a1 ;
var1='abc' ;
var2='def' ;
var3='ghi' ;
var4='abc' ;
var5='xyz' ;
var6='def' ;
run;
data a2 ;
set a1 ;
array apple(6) $ var1-var6 ;
array temp(6) $ temp1-temp6 ;
do i=1 to dim(apple);
if apple{i} in temp then call missing(apple{i});
else temp{i}=apple{i};
end;
drop i temp:;
run;
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.