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

Hi All,

 

Below is the example data.


data have;
infile datalines missover;
informat v1 -v5 $2.;
input v1-v5;
cards;
A A B A A
X A Y X Y
S M K H A
X A X
A B B
;
run;

I want to get the result in another column V6:
first row : A/B
Second row: X/A/Y
Third Row : S/M/K/H/A
Fourth Row: X/A
Fifth Row : A/B

 

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

Turn the duplicates into missing values (empty strings) and concatenate what's left.

data want;
set have;
array a v1-v5;
do i = 2 to dim(a);
    if whichc(a{i}, of a{*}) < i then call missing(a{i});
    end;
length x $10;
x = catx("/", of a{*});
drop i v:;
run;

 

PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

Turn the duplicates into missing values (empty strings) and concatenate what's left.

data want;
set have;
array a v1-v5;
do i = 2 to dim(a);
    if whichc(a{i}, of a{*}) < i then call missing(a{i});
    end;
length x $10;
x = catx("/", of a{*});
drop i v:;
run;

 

PG
Ksharp
Super User
data have;
infile datalines missover;
informat v1 -v5 $2.;
input v1-v5;
cards;
A A B A A
X A Y X Y
S M K H A
X A X
A B B
;
data want;
 set have;
 array x{5} $ 1 ;
 array v{5} $;
 n=0;
 do i=1 to dim(v);
  if v{i} not in x then do;n+1;x{n}=v{i};end;
 end;
 want=catx('/',of x{*});
 drop n i x: ;
run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 2 replies
  • 851 views
  • 3 likes
  • 3 in conversation