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
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;
Thank you !!
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
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
;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.