BookmarkSubscribeRSS Feed
thanikondharish
Fluorite | Level 6
Data EX;
Name='jhonson Peter clerk audits cinema movie running';
Run;
I have one data set ex now I want to split 10. Letters but the word should be full like
Length 10----> Johnson pe
So the above condition splitting the Peter so pe is coming in this case we should take only Johnson word.
Next continue the 10 length word so the next new variable columns has 'peter clerk' like that
So how
to do above scenario
5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

What does your desired result look like? Do you want an observation for each split or?

thanikondharish
Fluorite | Level 6
Yes
PeterClemmensen
Tourmaline | Level 20

Ok. Do you have more than one observation in your actual EX Data set?

Ksharp
Super User
Data EX;
Name='jhonson Peter clerk audits cinema movie running';
Run;
data want;
 set ex;
 length want _want $ 100;
 do i=1 to countw(name,' ');
   temp=scan(name,i,' ');
   _want=want;
   want=catx(' ',want,temp); 
   if length(want)>11 then do;want=_want;output;want=temp;end;
 end;
 output;
 drop temp _want i;
 run;
Astounding
PROC Star

Give an example of what you want if you have a name like "Bartholomew" instead of "Peter" ... something that is longer than 10 characters in a single word.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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
  • 5 replies
  • 1551 views
  • 0 likes
  • 4 in conversation