BookmarkSubscribeRSS Feed
shikhar6339
Calcite | Level 5

Data I have:

 

1 A,B,C

2 D

3 E,F

 

 

Data I want:

 

1 A

1 B

1 C

2 D

3 E

3 F

 

 

 

 

3 REPLIES 3
Kurt_Bremser
Super User
data want;
set have;
do i = i to countw(string,',');
  newstring = scan(string,i,',');
  output;
end;
drop i string;
run;

Set proper length for newstring as needed.

PeterClemmensen
Tourmaline | Level 20

Welcome to the SAS Community 🙂

 

data have;
input id var $20.;
datalines;
1 A,B,C
2 D
3 E,F
;

data want(keep=id newvar);
    set have;
    do i=1 to countw(var, ',');
        newvar=scan(var, i, ',');
        output;
    end;
run;

Result:

 

id  newvar
1   A
1   B
1   C
2   D
3   E
3   F
Ksharp
Super User
data have;
infile cards dlm=' ,' truncover;
input id var : $40. @;
do while(not missing(var));
 output;
 input var : $40. @;
end;
datalines;
1 A,B,C
2 D
3 E,F
;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 935 views
  • 1 like
  • 4 in conversation