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
;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 891 views
  • 1 like
  • 4 in conversation