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
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.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.