Hi all, I am quite confused about how to use the lengthn, cat, catx and substr functions all together for string manipulation. I am trying to add a variable that inserts a dash between the 2nd to last character and the last character of Item and wraps the value in parentheses. For example, Item 144L becomes (144-L). Use the LENGTHN, SUBSTR, CAT and CATX functions. The solution should be generalizable to any value of Item containing 2 or more characters. So far, I have been building the program using examples I have seen but I keep getting confused. Please can you help me fix my program and include explanations if u can. I just need to understand how all the functions work together to solve this problem. Thanks. data CustomerDB ;
input Customer & $18.
Item : $11. ;
datalines;
Bartco Corporation 143L
Cost Cutter's 142
Minimart Inc. 188SW
Bosco, LLC 908X321
K-MART. A122L
Food Unlimited 1898XVWX
Shop and Drop 24L
Shop Marty's 222X
Pet's are Us W100
Roger's Spirits 1522L
Artful Spirits 407XxxXxx
Up/Down mart Inc. ABCdefghxxx
;
data newTemp;
set CustomerDB;
if lengthn(Item) ge 3 then
secondtoLastRemoved = catx("-",(substr(Item,1,(lengthn(Item)-2))),(substr(Item,lengthn(Item), 1))
); /*Dropping Second to last characters from string?*/
else
secondtoLastRemoved = Item;
if findc(Item,'mart','i') gt 0 then
bool = 1; /*setting boolean for words that have the string "mart" in them */
else
bool = 0;
lowcaseCustomer = lowcase(compress(Customer,,'p')); /* Remove Punctuation and make letters lowercase */
run;
proc print data = newTemp;
title "CustomerDB string Manipulations";
run;
... View more