Having an array X you can sort it by value using CALL SORTN(OF X[*]); for numeric variables
or SORTC for character variables.
After sort just compare value of x(i) with x(i+1) to check for same values,
then get var names using function VNAME(X(i));
You may try next code:
/* starting code the same as of @smantha */
data have;
infile datalines dlm=" " dsd missover;
input Var1 $ var2 $ var3 $ var4 $ var5 $ var6 $;
length similar_char_vars similar_num_vars $32767.;
array _c{*} _character_;
array _n{*} _numeric_;
call sortN(_n(*));
call sortC(_c(*));
do i=1 to dim(_c)-1;
if _c(i) = _c(i+1) then put _N_= vname(_c(i)) vanme(_c(i+1));
end;
do i=1 to dim(_n)-1;
if _n(i) = _n(i+1) then put _N_= vname(_n(i)) vanme(_n(i+1));
end;
datalines;;
1 a 4 6 a 1
9 l 6 g l 5
8 d 5 y d
7 & 7 y 6
;;;
run;
Sorry, I tested the code and unfortunately some documented code did not work for me:
neither CALL SORTC(array_name(*));
nor CALL SORTN(array_name(*));
It seems that those procedures requires list of variable names.
Another issue found - after sorting the array the VNAME doesn't show the right
variable name.
I had some other issues, so please ignore that code.
I intend to open a new query to point those issues ans ask for future upgrade.
Shmuel
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.