BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AntoineA
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

1 REPLY 1
Astounding
PROC Star

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 1402 views
  • 1 like
  • 2 in conversation