BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5

Splitting the data in to differnt rows id name      value2              value3 1  a,b      a:1,b:1              a:2,b:2 2  a,b      a:3,b:4              a:3,b:4 3  a        a:5                  a:6 4  a,b,c,d  a:10,b:20 c:30 d:40  a:10,b:20 c:30 d:40 Output I am having a variable Name it should split base on the commas and the correspoding value(value2 and value3) sould come. id Name value2    value3 1  a  a:1    a:2 1  b  b:1    b:2 2  a  a:3    a:3 2  b  b:4      b:4 3  a  a:5    a:6 4  a  a:10    a:10 4  b  b:20    b:20 4  c    c:30    c:30 4  d    d:40    d:40 For ef you can view in txt

1 REPLY 1
Ksharp
Super User

EASY.

data have;
input id name & $20.     value2  & $20.            value3 & $20.;
cards;
1  a,b      a:1,b:1              a:2,b:2
2  a,b      a:3,b:4              a:3,b:4
3  a        a:5                   a:6
4  a,b,c,d  a:10,b:20 c:30 d:40   a:10,b:20 c:30 d:40 
;
run;
data want(drop=value: i n name);
 set have;
 length _name _value2 _value3 $ 20;
 n=max(countw(value2,', '),countw(value3,', '));
 do i=1 to n;
  _name=scan(name,i,', ');
  _value2=scan(value2,i,', ');
  _value3=scan(value3,i,', ');
  output;
 end;
run;

Ksharp

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
  • 1 reply
  • 721 views
  • 0 likes
  • 2 in conversation