BookmarkSubscribeRSS Feed
Sagar_Pawar
Fluorite | Level 6

data a;
input id name: $30.;
datalines;
1 sachin,ramesh,tendulkar
2 narendra,modi
3 modi

output wants:
id name
1 sachin
1 ramesh
1 tendulkar
2 narendra
2 modi
3 modi

4 REPLIES 4
Patrick
Opal | Level 21
data have;
  input id name: $30.;
  datalines;
1 sachin,ramesh,tendulkar
2 narendra,modi
3 modi
;

data want;
  set have;
  length name2 $10;
  drop name;
  do i=1 to countc(name,',')+1;
    name2=scan(name,i,',');
    output;
  end;
run;
Sagar_Pawar
Fluorite | Level 6

Thank you !!

Tom
Super User Tom
Super User

That is what the trailing @ is for in the INPUT statement.

data a;
  infile datalines dsd dlm=', ' truncover;
  input id @;
  do col=1 by 1 ;
    input name :$30. @;
    if name=' ' and col>1 then leave;
    output;
  end;
datalines;
1 sachin,ramesh,tendulkar
2 narendra,modi
3 modi
4
;

proc print;
run;

Result

Obs    id    col    name

 1      1     1     sachin
 2      1     2     ramesh
 3      1     3     tendulkar
 4      2     1     narendra
 5      2     2     modi
 6      3     1     modi
 7      4     1
Ksharp
Super User
data a;
infile cards dlm=' ,' truncover;
input id name :$80. @;
do while(not missing(name));
 output;
 input name :$80. @;
end;
datalines;
1 sachin,ramesh,tendulkar
2 narendra,modi
3 modi
;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 4 replies
  • 1085 views
  • 1 like
  • 4 in conversation