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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.