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

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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