My dataset consists a variable named as "REPORTING_ENTITY" in the form of string. Now, from that variable i want create a new dataset which consist a observations with keywords as ('Bank','Loan','Cooperative','SBI','Insurance') from "REPORTING_ENTITY" also want that strings get deleted from original dataset. I did something like:
data class.sample;
set work.sample;
where REPORTING_ENTITY contains ('Bank','Loan','Cooperative','SBI','Insurance');
run;
This will create a new dataset with mentioned keywords but it will not get deleted from orignal dataset..
Just to see if I understand correctly, you want a new variable i your new dataset based on the variable REPORTING_ENTITY, where you want the substring eg "Bank" to be deleted from the string such that eg "New York Bank" becomes "New York"? 🙂
no...... i want "newyork bank" to be seperated whole from existing dataset not only "bank"...plz help me on this...
So the entire observation? 🙂 If so then see @Kurt_Bremsers solution
I would do it like that:
data
class.sample
work.origsample
;
set work.sample;
if REPORTING_ENTITY contains ('Bank','Loan','Cooperative','SBI','Insurance')
then output class.sample;
else output work.origsample;
run;
Once you have verified that the step ran successfully, you can remove work.sample and rename work.origsample to work.sample.
I'd run that code but it shows error in log window as:
22-322 Syntax error, expecting one of the following: !, !!, &, (, ), *, **, +, ',', -, '.', /,
<, <=, <>, =, >, >=, ?, AND, EQ, EQT, EXCEPT, GE, GET, GT, GTT,
HAVING, IN, INTERSECT, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, OUTER,
UNION, ^, ^=, |, ||, ~, ~=.
68-185 The function CONTAINS is unknown, or cannot be accessed.......
plz help..... @PeterClemmensen @Kurt_Bremser @art297
The contains operator can only be used in a datastep's where clause. However, you can accomplish the same thing with a series of statements that use the FIND function. Take a look at: http://support.sas.com/kb/43/303.html
HTH,
Art, CEO, AnalystFinder.com
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.