DATA Step, Macro, Functions and more

How to keep 2 variables values using the SUBSTR function

Accepted Solution Solved
Reply
New Contributor
Posts: 4
Accepted Solution

How to keep 2 variables values using the SUBSTR function

[ Edited ]

Hi,

 

I'm creating a second dataset using the SUBSTR function to keep all the data I need based on variables values.

For the variable DocClause, I have two different values I would like to keep in the dataset I am creating, "MR" and "MR14".

 

The code below only keeps the value "MR14" on the created dataset.

 

Is there a way to keep "MR14" and "MR" in my new dataset using the SUBSTR function?

DATA MEMOIRE.CDS_BBB_US_MR;
	SET MEMOIRE.CDS_2001_2015;
	IF SUBSTR(ImpliedRating,2,3)="BBB";
	IF SUBSTR(Country,2,13)="United States";
	IF SUBSTR(DocClause,2,2)="MR";
	IF SUBSTR(DocClause,2,4)="MR14";
	IF SUBSTR(Sector,2,10)="Government" THEN delete;
RUN;

 Thank you


Accepted Solutions
Solution
‎04-12-2016 01:27 PM
Super User
Posts: 5,081

Re: How to keep 2 variables values using the SUBSTR function

The simplest solution would be to get rid of this statement:

 

IF SUBSTR(DocClause,2,4)="MR14" ;

 

The condition relating to "MR" would already include all of the "MR14" cases.

 

It's important to note that the IF conditions operate as if the word AND were joining them.  For an observation to make it all the way through into the final data set, it must satisfy all of the IF statements.  If it makes sense, you can join multiple conditions using the word OR.

View solution in original post


All Replies
Solution
‎04-12-2016 01:27 PM
Super User
Posts: 5,081

Re: How to keep 2 variables values using the SUBSTR function

The simplest solution would be to get rid of this statement:

 

IF SUBSTR(DocClause,2,4)="MR14" ;

 

The condition relating to "MR" would already include all of the "MR14" cases.

 

It's important to note that the IF conditions operate as if the word AND were joining them.  For an observation to make it all the way through into the final data set, it must satisfy all of the IF statements.  If it makes sense, you can join multiple conditions using the word OR.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 195 views
  • 1 like
  • 2 in conversation