Hello All,
I am having troubles with my IF ELSE statement. It is not assigning the values properly for some reason.
I am trying to code a new variables Code' to be:
1 if Case is "I25.YY"
2 if Case is "150.YY"
3 if Case is "163.YY" and
4 for any other value
and I want a new variable 'Death'
to be 1 if Code = 1,2,3
and 0 if Code = 4
So I created a substring of Case named "Placeholder" to only contain the first three characters to make the new variable CODE easier to recognize. But when I input my IF ELSE statements, it doesn't assign the values correctly and I don't know why. Please help:
Dataset I have that isn't correct
obs | ssn | date | Case | placeholder | Code | Death | |
101 | 252-81-5641 | 2016-12-30 | I22.13 | I22 | 4 | 0 |
102 | 112-32-1992 | 2016-06-27 | I24.23 | I24 | 4 | 0 |
103 | 498-73-1990 | 2016-10-16 | I25.33 | I25 | 4 | 0 |
104 | 372-39-2093 | 2016-09-05 | I25.42 | I25 | 4 | 0 |
105 | 127-41-0067 | 2016-10-13 | I25.19 | I25 | 4 | 0 |
106 | 478-37-8847 | 2015-10-30 | I25.91 | I25 | 4 | 0 |
107 | 528-08-1992 | 2015-05-26 | I25.21 | I25 | 4 | 0 |
108 | 574-46-0715 | 2015-09-08 | I25.31 | I25 | 4 | 0 |
109 | 068-44-0495 | 2015-03-19 | I25.92 | I25 | 4 | 0 |
110 | 494-72-4043 | 2016-10-13 | I39.41 | I39 | 4 | 0 |
111 | 018-93-3430 | 2016-07-03 | I41.21 | I41 | 4 | 0 |
112 | 538-92-4707 | 2016-11-20 | I49.13 | I49 | 4 | 0 |
113 | 798-08-2998 | 2016-10-22 | I50.32 | I50 | 4 | 0 |
114 | 424-92-9797 | 2016-07-04 | I50.21 | I50 | 4 | 0 |
115 | 418-15-3055 | 2015-08-30 | I50.91 | I50 | 4 | 0 |
116 | 434-75-5248 | 2016-10-07 | I50.11 | I50 | 4 | 0 |
117 | 423-12-7794 | 2016-05-29 | I50.42 | I50 | 4 | 0 |
118 | 326-80-9737 | 2015-04-17 | I50.91 | I50 | 4 | 0 |
119 | 524-43-5860 | 2016-12-12 | I50.13 | I50 | 4 | 0 |
120 | 986-08-2045 | 2015-05-25 | I50.13 | I50 | 4 | 0 |
121 | 013-78-8406 | 2015-08-16 | I62.92 | I62 | 4 | 0 |
122 | 484-63-7323 | 2015-05-23 | I63.42 | I63 | 3 | 1 |
Dataset I want
obs | ssn | date | Case | Death |
101 | 252-81-5641 | 2016-12-30 | I22.13 | 4 |
102 | 112-32-1992 | 2016-06-27 | I24.23 | 4 |
103 | 498-73-1990 | 2016-10-16 | I25.33 | 1 |
104 | 372-39-2093 | 2016-09-05 | I25.42 | 1 |
105 | 127-41-0067 | 2016-10-13 | I25.19 | 1 |
106 | 478-37-8847 | 2015-10-30 | I25.91 | 1 |
107 | 528-08-1992 | 2015-05-26 | I25.21 | 1 |
108 | 574-46-0715 | 2015-09-08 | I25.31 | 1 |
109 | 068-44-0495 | 2015-03-19 | I25.92 | 1 |
110 | 494-72-4043 | 2016-10-13 | I39.41 | 4 |
111 | 018-93-3430 | 2016-07-03 | I41.21 | 4 |
112 | 538-92-4707 | 2016-11-20 | I49.13 | 4 |
113 | 798-08-2998 | 2016-10-22 | I50.32 | 2 |
114 | 424-92-9797 | 2016-07-04 | I50.21 | 2 |
115 | 418-15-3055 | 2015-08-30 | I50.91 | 2 |
116 | 434-75-5248 | 2016-10-07 | I50.11 | 2 |
117 | 423-12-7794 | 2016-05-29 | I50.42 | 2 |
118 | 326-80-9737 | 2015-04-17 | I50.91 | 2 |
119 | 524-43-5860 | 2016-12-12 | I50.13 | 2 |
120 | 986-08-2045 | 2015-05-25 | I50.13 | 2 |
121 | 013-78-8406 | 2015-08-16 | I62.92 | 4 |
122 | 484-63-7323 | 2015-05-23 | I63.42 | 3 |
Code I have that is not currently working
DATA Want.NDI;
SET Have.NDI;
PLACEHOLDER = SUBSTR(ICD10, 1, 3.);
IF PLACEHOLDER = 'I25' THEN Code = 1;
IF PLACEHOLDER = 'I50' THEN Code = 2;
IF PLACEHOLDER = 'I63' THEN Code = 3;
ELSE Code = '4';
IF Code = 4 THEN death = 0;
ELSE death = 1;
DROP PLACEHOLDER;
RUN;
other information that might be useful:
SAS studio~~ Release: 3.8 (Basic Edition)
no errors or warnings in log
**Original Post has been altered to avoid being googlesearched for future classes*;
IF PLACEHOLDER = 'I63' THEN CODCD = 3;
ELSE CODCD = '4';
This statement means that ALL values other than I63 will result in codcd =4; you need to make the branches mutually exclusive, and the best way to do that is the data step SELECT:
select (placeholder);
when ('I25') codcd = 1;
when ('I50') codcd = 2;
when ('I63') codcd = 3;
otherwise codcd = 4;
end;
(with your original code, you would need to insert ELSE branches:
IF PLACEHOLDER = 'I25' THEN CODCD = 1;
else IF PLACEHOLDER = 'I50' THEN CODCD = 2;
else IF PLACEHOLDER = 'I63' THEN CODCD = 3;
ELSE CODCD = '4';
Hi Deanna,
I happen to be in Lala's Programming course as well and for this portion of the project. I did the same exact thing for my IF THEN statements that you did
However for next portion of your code, I used different numbers:
IF CODCD = (1, 2, 3) THEN RELDEATHIND = 1;
ELSE RELDEATHIND = 0;
Lastly, I did not DROP the PLACEHOLDER in my code either.
Try these changes and see if you have success with creating the dataset then.
De'Janae'
@DeJanae07 wrote:
Hi Deanna,
I happen to be in Lala's Programming course as well and for this portion of the project. I did the same exact thing for my IF THEN statements that you did below:
PLACEHOLDER = SUBSTR(ICD10, 1, 3.);
IF PLACEHOLDER = 'I25' THEN CODCD = 1;
IF PLACEHOLDER = 'I50' THEN CODCD = 2;
IF PLACEHOLDER = 'I63' THEN CODCD = 3;
ELSE CODCD = '4';
However for next portion of your code, I used different numbers:
IF CODCD = (1, 2, 3) THEN HYPRELDEATHIND = 1;
ELSE HYPRELDEATHIND = 0;Lastly, I did not DROP the PLACEHOLDER in my code either.
Try these changes and see if you have success with creating the dataset then.
De'Janae'
You really want to check the value of your CODCD variable for ICD "I25" and "I50".
If you didn't drop your place holder variable then you may want to try this code (a moderately common way to check recoding)
Proc freq data=have; tables placeholder *codcd/list missing; run;
This sort of code will generate one line for each combination of Placeholder and Codcd, including missing values if any. This is a relatively easy check on single variable recoding as you are doing.
Hi Deanna,
It looks like you specify CODCD with quotations in your first IF statement: CODCD = '4';
But then in your second statement you have if without quotations: CODCD = 4
If you put quotations around the 4 in the second statement does that solve the problem?
Samantha
Hello,
Try using this code below, the issue might be that you would have to format them again as shown below.
I hope it helps!
ICD10a = SUBSTR(ICD10,1,3);
IF ICD10a = 'I25' THEN CODCd = 1;
ELSE IF ICD10a = 'I50' THEN CODCd = 2;
ELSE IF ICD10a = 'I63' THEN CODCd = 3;
ELSE CODCd = 4;
IF CODCd IN(1, 2, 3) THEN HypRelDeathInd = 1;
ELSE HypRelDeathInd = 0;
DROP ICD10a;
RUN;
To get the formats as to how you mentioned in the second table, try using this:
PROC FORMAT;
VALUE CODCd
1 = "I25.XX"
2 = "I50.XX"
3 = "I63.XX"
4 = "Other COD";
RUN;
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.