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.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.