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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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