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: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 822 views
  • 3 likes
  • 3 in conversation