BookmarkSubscribeRSS Feed
bits
Fluorite | Level 6

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..

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

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"? 🙂

bits
Fluorite | Level 6

no...... i want "newyork bank" to be seperated whole from existing dataset not only "bank"...plz help me on this...

PeterClemmensen
Tourmaline | Level 20

So the entire observation? 🙂 If so then see @Kurt_Bremsers solution

Kurt_Bremser
Super User

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.

 

bits
Fluorite | Level 6

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

art297
Opal | Level 21

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1742 views
  • 1 like
  • 4 in conversation