🔒 This topic is solved and locked.
Need further help from the community? Please
sign in and ask a new question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Posted 04-07-2020 03:46 AM
(749 views)
Cards;
Rama chandra Vikas murthy
V v s lakshman
Siva sanker Prasad Kumar
Guru' Prasad
Guru' raaj gopal govind dasu
;
I want output like this
First_name: first'word
Last_name: last word
Middle name:all the words apart from first name and last name
Rama chandra Vikas murthy
V v s lakshman
Siva sanker Prasad Kumar
Guru' Prasad
Guru' raaj gopal govind dasu
;
I want output like this
First_name: first'word
Last_name: last word
Middle name:all the words apart from first name and last name
1 ACCEPTED SOLUTION
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;