BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Shmuel
Garnet | Level 18

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

Emma8
Quartz | Level 8
Thanks, but the output is not what I want to. I want only get var2 and var5 (compare all obs except missing).
Shmuel
Garnet | Level 18

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;
Emma8
Quartz | Level 8
Hi. Can you first create the have data and then write the code? I mean I have another huge sas data data I cannot use infile -when I remove and use my data —it has a warning “undefined array -also line call and column undetermined for call sortn...
Thank you.
Shmuel
Garnet | Level 18

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

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

Explore 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
  • 19 replies
  • 5419 views
  • 4 likes
  • 4 in conversation