Hi,
Is there a function or a loop which can compress multiple strings in one large string.
for ex: if (salary >= 0 & salary <= 25000) then salcat_1 = "C";
output should look like : salary >= 0 & salary <= 25000 salcat_1 = "C"
Appreciate your help on this.
Hi,
Could you please explain criterian for removing multiple strings?
if (salary >= 0 & salary <= 25000) then salcat_1 = "C";
In the string above , you are eliminating "if" and "then". Will this be the same always? Every time we need to eliminate only "If" and "else"? Please be more explicit.
I am importing a file which has few strings {ex: IF THEN ELSE SELECT etc} ,I now wanted to remove those strings{not pre post text,only the above mentioned words} from the dataset .
As i have split those in to observations,I am in serach of a best approach/logic, Just posted a basic example below.
input : if (salary >= 0 & salary <= 25000) then salcat_1 = "C";
Output : salary >= 0 & salary <= 25000 salcat_1 = "C"
What about the ()? What about other characters? If you just want to remove those then tranwrd() or compress() can do it:
data want; set have; string=tranwrd(string,"if",""); string=tranwrd(string,"then",""); run;
However I question what you are doing, you appear to be reading in code, which can make parsing more difficult than just removing some characters, e.g.
if (abc="I go on holiday if I booked it) then result="Sometimes (always)";
will result in:
(abc="I go on holiday I booked it) result="Sometimes (always)";
Personally, I would look at other methods to do this, including looking at the documentation - you do have that?
@lokeshbm wrote:
I now wanted to remove those strings{not pre post text,only the above mentioned words} from the dataset .
I can't see any list of mentioned words or characters. You need to define those.
Then you can use a combination of translate or transwrd functions.
Regular expressions can probably help as well.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.