hi team,
i want to extract single word coming before and after dot(.)
for example:
string : find all words before and after dot.like this; select lib.tab , lib1.tab1;
Output: dot.like lib.tab, lib1.tab1
The idea is to extract lib_name.table_name from sas code line
I would find the position of the dot (period) using the Index function and then scan left or right from there.
Jim
Here's some sample code:
%LET String = I love apple.pie and ice cream;
%LET Position = %SYSFUNC(INDEXC(&String,.));
%LET Word_Before = %SYSFUNC(SCAN(%QSUBSTR(&String, 1, %EVAL(&Position - 1)), -1));
%LET Word_After = %SYSFUNC(SCAN(%QSUBSTR(&String, %EVAL(&Position + 1)), 1));
OPTION NOSOURCE;
%PUT NOTE: &=Position;
%PUT NOTE- &=Word_Before;
%PUT NOTE- &=Word_After;
OPTION SOURCE;
Results:
NOTE: POSITION=13 WORD_BEFORE=apple WORD_AFTER=pie
Note that this code may not give you the results you want if there are multiple periods in one text string.
Jim
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.