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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register 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.

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
  • 617 views
  • 3 likes
  • 3 in conversation