BookmarkSubscribeRSS Feed
R_Win
Calcite | Level 5
Hi
i am having 200 words i want the last 10 to 15 words to be printed
here is the example

'Environmental Studies'

in this word i want the 'udi' word .How can i do this as i said this is small example i am having 250-300 words and i cant cont by using substr how can i do this
4 REPLIES 4
LinusH
Tourmaline | Level 20
I'm not sure I understand what you try to accomplish here.If you know what words (or extracts) to search for you can start looking at the FIND function.
Maybe you can give us some more examples and expected result.

/Linus
Data never sleeps
Flip
Fluorite | Level 6
If you are refering to characters, not words simply do:
data _null_;
x = 'Environmental Studies' ;
y = substr(x, length(x) -4, 3);
put y;
run;

You stated 10 - 15, but your example showed 3 of the last 5.
R_Win
Calcite | Level 5
Thqs for the Reply
deleted_user
Not applicable
this code takes a character string of words and just gets the last 3 words. I purposely made the length of the words different. Don't know if this is the kind of thing you wanted to do.
*****************************************

data temp;
wordstring = 'abc defg hijkl m nop qrstuvw xyz';
end1 = length(wordstring);
array start{*} start1-start3;
array end{*} end1-end3;
array lngth{*} lngth1-lngth3;
start1 = anyspace(wordstring,-end1) + 1;
lngth1 = end1 - start1 + 1;
word1 = substr(wordstring,start1,lngth1);
do i = 2 to 3;
start{i} = anyspace(wordstring,-(start{i-1}-2)) + 1;
lngth{i} = start{i-1} - start{i} -1;
end;
word2 = substr(wordstring,start2,lngth2);
word3 = substr(wordstring,start3,lngth3);
run;
proc print data = temp;
var wordstring word1-word3; run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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