DATA Step, Macro, Functions and more

create a new dataset based on certin keywords from existing dataset

Reply
Occasional Contributor
Posts: 19

create a new dataset based on certin keywords from existing dataset

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

PROC Star
Posts: 746

Re: create a new dataset based on certin keywords from existing 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"? Smiley Happy

Occasional Contributor
Posts: 19

Re: create a new dataset based on certin keywords from existing dataset

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

PROC Star
Posts: 746

Re: create a new dataset based on certin keywords from existing dataset

So the entire observation? Smiley Happy If so then see @KurtBremsers solution

Super User
Posts: 7,782

Re: create a new dataset based on certin keywords from existing dataset

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.

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor
Posts: 19

Re: create a new dataset based on certin keywords from existing dataset

[ Edited ]
Posted in reply to KurtBremser

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..... @draycut @KurtBremser @art297

PROC Star
Posts: 7,474

Re: create a new dataset based on certin keywords from existing dataset

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

Ask a Question
Discussion stats
  • 6 replies
  • 152 views
  • 1 like
  • 4 in conversation