Hello,
I'm using this statement in my code:
IF substr(ICD10Code,1,1)="T21" & substr(ICD10Code,8,1) in ("A", "B", "C") THEN MIC=1;
However, When ICD10Code value is T21.06XA, SAS is returning MIC =0
Any idea why this is happening?
Thank you !
I'm sorry the correct IF statement I'm using is:
IF substr(ICD10Code,1,3)="T21" & substr(ICD10Code,8,1) in ("A", "B", "C") THEN MIC=1;
If you do PROC CONTENTS on this dataset, what's the length of the ICD10 code variable? It could be an alignment issue. You could try:
ICD10Code=compress(ICD10code);
** and then just use your existing IF statement ;
** if that fails, just try seeing what the two substr() calls produce: ;
first3=substr(ICD10Code,1,3);
last1=substr(ICD10Code,8,1);
You could also use a picture format or regex, but might as well keep it simple.
Make sure that T21 is actually starting in the first byte of ICD10CODE.
Perhaps you have leading spaces that you cannot see when you PRINT the value (especially if you use ODS printing because it removes the leading spaces).
Perhaps your variable has a FORMAT attached to it that makes it PRINT something that is different than what is actually stored in the variable.
Try printing the values using the $QUOTE. format as adding that will help with both of those potential issues.
Troubleshooting 101, print the values of your operations to the LOG.
ICD10Code_1 = substr(ICD10Code,1,1);
put ICD10Code_1=;
Alignment issues can be solved using LEFT() function.
I believe that this is what you want
IF substr(ICD10Code,1,1)=:"T21" & substr(ICD10Code,8,1) in ("A", "B", "C") THEN MIC=1;
Please note there is a colon after the equal sign; and so =: indicates starts with, which seems to be what you want.
@PaigeMiller wrote:IF substr(ICD10Code,1,1)=:"T21" & substr(ICD10Code,8,1) in ("A", "B", "C") THEN MIC=1;
I assume you mean
IF ICD10Code=:"T21" & substr(ICD10Code,8,1) in ("A", "B", "C") THEN MIC=1;
because substr(ICD10Code,1,1)=:"T21" would be equivalent to ICD10Code=:"T".
But ICD10Code=:"T21" is equivalent to substr(ICD10Code,1,3)="T21" (assuming that ICD10Code has length >=3), which did not meet @Ihsan-Mahdi's expectations.
So I would look at the values of ICD10Code in $HEX. format (or use @Tom's suggestions) to find out why the IF condition is not met for a value that looks like "T21.06XA".
You've got some good recommendations already.
You could also add a PUT statement to show the values of ICD10Code and Mic. If the PUT statement does not execute, that means you don't actually have the value T21.06XA in your data (maybe there are leading spaces, or capitalization issues, or... )
data want ;
set have ;
IF substr(ICD10Code,1,3)="T21" & substr(ICD10Code,8,1) in ("A", "B", "C") THEN MIC=1;
IF ICD10Code="T21.06XA" then put ICD10Code= Mic= ;
run ;
And of course it always helps to look at your data:
proc freq data=have ;
tables ICD10Code*Mic/missing list ;
format _all_ ;
run ;
The IF statement you posted works, so it's likely that the value of ICD10Code is not matching your expectation.
1 data have ;
2 ICD10Code="T21.06XA" ;
3 run ;
NOTE: The data set WORK.HAVE has 1 observations and 1 variables.
4
5 data want ;
6 set have ;
7 IF substr(ICD10Code,1,3)="T21" & substr(ICD10Code,8,1) in ("A", "B", "C") THEN MIC=1;
8 IF ICD10Code="T21.06XA" then put ICD10Code= Mic= ;
9 run ;
ICD10Code=T21.06XA MIC=1
NOTE: There were 1 observations read from the data set WORK.HAVE.
NOTE: The data set WORK.WANT has 1 observations and 2 variables.
Assign a $HEX format of suitable length (double the defined length of the variable) and look at the hex codes. This will give you an idea of what is really stored there (leading blanks, possible UTF characters, non-printable characters).
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.
Ready to level-up your skills? Choose your own adventure.