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

AI Navigator GIF.gif


Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.

Check it out on Microsoft Marketplace →

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 1747 views
  • 0 likes
  • 2 in conversation