data have;
input x $40.;
call scan(x,1,p1,l1,' ');
call scan(x,-1,p2,l2,' ');
first=substr(x,1,l1);
last=substr(x,p2);
middle=substr(x,l1+1,p2-l1-1);
Cards;
Rama chandra Vikas murthy
V v s lakshman
Siva sanker Prasad Kumar
Guru' Prasad
Guru' raaj gopal govind dasu
;
proc print;run;
Scan() with 1 gets you the first, scan() with -1 the last word.
All others can be extracted in a do loop from 2 to countw() - 1.
data have;
input x $40.;
call scan(x,1,p1,l1,' ');
call scan(x,-1,p2,l2,' ');
first=substr(x,1,l1);
last=substr(x,p2);
middle=substr(x,l1+1,p2-l1-1);
Cards;
Rama chandra Vikas murthy
V v s lakshman
Siva sanker Prasad Kumar
Guru' Prasad
Guru' raaj gopal govind dasu
;
proc print;run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.