BookmarkSubscribeRSS Feed
Deanna_Payne
Obsidian | Level 7

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

obsssndateCaseplaceholderCodeDeath 
101252-81-56412016-12-30I22.13I2240 
102112-32-19922016-06-27I24.23I2440 
103498-73-19902016-10-16I25.33I2540 
104372-39-20932016-09-05I25.42I2540 
105127-41-00672016-10-13I25.19I2540 
106478-37-88472015-10-30I25.91I2540 
107528-08-19922015-05-26I25.21I2540 
108574-46-07152015-09-08I25.31I2540 
109068-44-04952015-03-19I25.92I2540 
110494-72-40432016-10-13I39.41I3940 
111018-93-34302016-07-03I41.21I4140 
112538-92-47072016-11-20I49.13I4940 
113798-08-29982016-10-22I50.32I5040 
114424-92-97972016-07-04I50.21I5040 
115418-15-30552015-08-30I50.91I5040 
116434-75-52482016-10-07I50.11I5040 
117423-12-77942016-05-29I50.42I5040 
118326-80-97372015-04-17I50.91I5040 
119524-43-58602016-12-12I50.13I5040 
120986-08-20452015-05-25I50.13I5040 
121013-78-84062015-08-16I62.92I6240 
122484-63-73232015-05-23I63.42I6331
 

 

Dataset I want

obsssndateCaseDeath
101252-81-56412016-12-30I22.134
102112-32-19922016-06-27I24.23

4

103498-73-19902016-10-16I25.331
104372-39-20932016-09-05I25.421
105127-41-00672016-10-13I25.191
106478-37-88472015-10-30I25.911
107528-08-19922015-05-26I25.211
108574-46-07152015-09-08I25.311
109068-44-04952015-03-19I25.921
110494-72-40432016-10-13I39.414
111018-93-34302016-07-03I41.214
112538-92-47072016-11-20I49.134
113798-08-29982016-10-22I50.322
114424-92-97972016-07-04I50.212
115418-15-30552015-08-30I50.912
116434-75-52482016-10-07I50.112
117423-12-77942016-05-29I50.422
118326-80-97372015-04-17I50.912
119524-43-58602016-12-12I50.132
120986-08-20452015-05-25I50.132
121013-78-84062015-08-16I62.924
122484-63-73232015-05-23I63.423

 

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*;

5 REPLIES 5
Kurt_Bremser
Super User
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';
DeJanae07
Calcite | Level 5

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' 

ballardw
Super User

@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.

sjbothwell
Calcite | Level 5

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

bshiferaw27
Fluorite | Level 6

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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 5 replies
  • 1818 views
  • 1 like
  • 6 in conversation