Help using Base SAS procedures

Reg:Characters from Last

Reply
Regular Contributor
Posts: 229

Reg:Characters from Last

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
Super User
Posts: 5,258

Re: Reg:Characters from Last

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
Super Contributor
Posts: 359

Re: Reg:Characters from Last

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.
Regular Contributor
Posts: 229

Re: Reg:Characters from Last

Thqs for the Reply
N/A
Posts: 0

Re: Reg:Characters from Last

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;
Ask a Question
Discussion stats
  • 4 replies
  • 119 views
  • 0 likes
  • 4 in conversation