I have a sentence "Sacramento is the capital of California" and am told to delete the words before the word "capital" and keep the rest. Now, the code has to be written so that if the word "capital" moves around then everything before it will be deleted. For example, "The capital of California is Sacramento" then only "The" in this sentence will be removed, whereas in the previous sentence "Sacramento is the" would have been removed.
Help please! Thanks 🙂
Hello,
I think you want the variable 'c' in the dataset 'want' :
data have;
a="Sacramento is the capital of California"; output;
a="The capital of California is Sacramento"; output;
run;
data want;
set have;
b=indexw(a,'capital');
c=substr(a,b);
d=substr(a,b+length('capital'));
run;
/* end of program */
Kind regards,
Koen
Hello,
I think you want the variable 'c' in the dataset 'want' :
data have;
a="Sacramento is the capital of California"; output;
a="The capital of California is Sacramento"; output;
run;
data want;
set have;
b=indexw(a,'capital');
c=substr(a,b);
d=substr(a,b+length('capital'));
run;
/* end of program */
Kind regards,
Koen
You can also use the FINDW function.
I would not use the SCAN function (you cannot scan for a whole word).
Koen
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.