Hi all,
I'm trying to complete a mapping of ICD10 codes to conditions by filling in missing values for variable "condition". I've created a variable icd10_grp that will identify groups of codes (by their first three digits). Within these groups I want to fill in the missing condition value with one of the present values (for condition) in the same group but ONLY when all the values in the group are the same. I've tried to use the update statement and that works when the missing value is not the first one (but doesn't discern if all values in group are the same). I've also tried coalesce function and it runs without error but the new column is still blank (and it doesn't discern if all values in group are the same either). How can I adjust the programming to identify all same values of condition within a group and then use that value to replace the missing one?
Thank you.
icd10 mapping to conditions
Product: Base SAS via Enterprise Guide 8.2
Release: 9.04.01 M6P110718
OS: Linux
SQL is usually easier.
Something like:
proc sql;
create table want as
select *,
case when max(condition)=min(condition) then 'Constant'
else 'Mixed'
end as cond_status,
case when not missing(condition) then condition
when missing(condition) and calculated status='Constant' then max(condition) else ''
end as new_condition
from yourTable
group by icd_grp;
quit;
Untested code as no data
SQL is usually easier.
Something like:
proc sql;
create table want as
select *,
case when max(condition)=min(condition) then 'Constant'
else 'Mixed'
end as cond_status,
case when not missing(condition) then condition
when missing(condition) and calculated status='Constant' then max(condition) else ''
end as new_condition
from yourTable
group by icd_grp;
quit;
Untested code as no data
Making progress! Current error message. TY for help.
@Reeza wrote:
Two single quotes to indicate blank/missing.
Since SAS stores character variables as fixed length values padded with blanks it is clearer to include the space between the quotes.
then max(condition) else ' '
@Clo13 wrote:
Hi Reeza,
Thank you! Question, toward the end of the code is that an open/single quotation " before end as new_condition
without a closing quotation "?
Check closely. Looks to be two single quotes with nothing between to assign a missing value to a character variable.
Copy the line of code into any window you can edit and attempt to delete (backspace) the quote. Only one goes away.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.