Can we use string as delimiter.
like . scan(word,"AND",1);
@Aman4SAS wrote:
Can we use string as delimiter.
like . scan(word,"AND",1);
See it this gives you enough to get started.
data example; x="This is a phrase with the word and embedded"; newx = tranwrd(x,' and ','+'); y=scan(newx,1,'+'); run;
The spaces around the ' and ' are there to get and as word so it does not get replaced inside words like "sand".
Use a character such as the + that 1) will not appear in your data and 2) is not a normal delimiter for the scan function so you get breaks where you expect it.
TRANWRD function is case sensitive. You may need either multiple passes through TRANWRD if you need " And " as well as " and " " AND " and so forth. Or UPCASE or LOWCASE the whole string.
Have you read the manual:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000214639.htm
Particularly:
charlist
specifies an optional character expression that initializes a list of characters. This list determines which characters are used as the delimiters that separate words. The following rules apply:
By default, all characters in charlist are used as delimiters.
If you specify the K modifier in the modifier argument, then all characters that are not in charlist are used as delimiters.
Tip: | You can add more characters to charlist by using other modifiers. |
The string you provide is not used "as is", any place where A, N, or D is found is a delimiter. Use substr() and findw()
@Aman4SAS wrote:
Can we use string as delimiter.
like . scan(word,"AND",1);
See it this gives you enough to get started.
data example; x="This is a phrase with the word and embedded"; newx = tranwrd(x,' and ','+'); y=scan(newx,1,'+'); run;
The spaces around the ' and ' are there to get and as word so it does not get replaced inside words like "sand".
Use a character such as the + that 1) will not appear in your data and 2) is not a normal delimiter for the scan function so you get breaks where you expect it.
TRANWRD function is case sensitive. You may need either multiple passes through TRANWRD if you need " And " as well as " and " " AND " and so forth. Or UPCASE or LOWCASE the whole string.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.