Help using Base SAS procedures

Concatenate into single row!!!

Accepted Solution Solved
Reply
Regular Contributor
Posts: 168
Accepted Solution

Concatenate into single row!!!

Hi All,

Data have;

input id    mut $;

cards;

100    mut1

100    nomut

100    mut3

101    mut3

101    mut4

105    mut5

105    nomut

105    mut6

;

run;

i want like this

100           mut1/nomut/mut3

101           mut3/mut4

105           mut5/nomut/mut6

Thanks in Advance

Sam



Accepted Solutions
Solution
‎11-15-2012 01:56 PM
PROC Star
Posts: 7,416

Re: Concatenate into single row!!!

Here is one way to do it, but this would leave it up to you to specify the length needed to capture the new field:

data want (drop=mut);

  set have;

  by id;

  length newfield $100;

  retain newfield;

  if first.id then newfield=mut;

  else newfield=catx('/',newfield,mut);

  if last.id then output;

run;

View solution in original post


All Replies
Solution
‎11-15-2012 01:56 PM
PROC Star
Posts: 7,416

Re: Concatenate into single row!!!

Here is one way to do it, but this would leave it up to you to specify the length needed to capture the new field:

data want (drop=mut);

  set have;

  by id;

  length newfield $100;

  retain newfield;

  if first.id then newfield=mut;

  else newfield=catx('/',newfield,mut);

  if last.id then output;

run;

Regular Contributor
Posts: 168

Re: Concatenate into single row!!!

Thank you so much Art!!!!


🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 184 views
  • 0 likes
  • 2 in conversation