Hi,
I have this SAS code that I need to use so I can have the snomed codes to cover all the types of result texts that I have in excel sheet.
if test_loinc="94558-4" then do; /*Note: this is an antigen test*/
result_snomed=10828004;
where (test_result="Positive"
or test_result="POSITIVE"
or test_result="positive");
result_snomed=260373001;
where (test_result="Detected"
or test_result="DETECTED"
or test_result="detected");
result_snomed=260385009;
where (test_result="Negative"
or test_result="NEGATIVE"
or test_result="negative");
result_snomed=260415000;
where (test_result="Not Detected"
or test_result="NOT DETECTED"
or test_result="not detected"
or test_result="Not detected");
end;
else if test_loinc="94759-8" then do; /*Note: this is a PCR test*/
result_snomed=10828004;
where (test_result="Positive"
or test_result="POSITIVE"
or test_result="positive");
result_snomed=260373001;
where (test_result="Detected"
or test_result="DETECTED"
or test_result="detected");
result_snomed=125154007;
where (test_result="Unsatisfactory"
or test_result="UNSATISFACTORY"
or test_result="unsatisfactory");
result_snomed=260385009;
where (test_result="Negative"
or test_result="NEGATIVE"
or test_result="negative");
result_snomed=260415000;
where (test_result="Not Detected"
or test_result="NOT DETECTED"
or test_result="not detected"
or test_result="Not detected");
result_snomed=280416009;
where (test_result="Indeterminate"
or test_result="INDETERMINATE"
or test_result="indeterminate");
result_snomed=419984006;
where (test_result="Inconclusive"
or test_result="INCONCLUSIVE"
or test_result="inconclusive");
end;
if test_loinc="94558-4" then do; /*Note: this is an antigen test*/
220 result_snomed=10828004;
221 where (test_result="Positive"
222 or test_result="POSITIVE"
223 or test_result="positive");
ERROR: WHERE clause operator requires compatible variables.
Thank you.
You are trying to compare a numeric variable named TEST_RESULT to a character string. You can't do that. You have to compare numeric to numeric, or character to character.
it is possible that numeric TEST_RESULT is formatted to appear as character; that would still require you to compare it to a numeric value. Use PROC CONTENTS to find out how TEST_RESULT is formatted.
Hello,
The where statement in a data step has a global effect and drops the observations that don't
match the condition before executing the data step intructions.
Thus, it does not make sense to condition these where statements as they will all be taken into account
at the program execution.
Before resolving this type mismatch problem, you might want to reconsider the logic of
your program.
Can you explain on a simplified example what you are trying to achieve ?
You have two serious mistakes here:
I guess that you should use the conditions in the IF statements; for more detailed help, supply some example data in usable form (DATA step with DATALINES, NOT Excel files or screenshots!), and what you intend to have as a result from that.
data; input name $ test_loinc $ test_result $; datalines; John 94759-8 Positive Michelle 94558-4 Not detected
Grace 94759-8 DETECTED ;
So the issue is that we're getting an excel sheet from a hospital that have different variables (in additition to the test_result and test_loinc) and we need to import into to our system. They use only 2 loincs (tests) (used in the example) and the result comes in different formats such as DETECTED, Detected, Positive, positive... etc. What I needed to do is to code all different result formats into the standard snomed (results) codes such as 10828004 for all postive results because our system accepts only codes for loincs and snomeds. BTW I'm not sure if the test_result is a character or numerical but I'm assuming it's a character in the example! Thank you
Can you show us a portion of the data set from the imported spreadsheet by following these instructions , and not via any other method. Do not attach the Excel file, most people will not download it.
Start with a "brute force" approach like this:
select (test_loinc);
when ("94759-8") do;
select (upcase(test_result));
when ("POSITIVE") result_snomed = 260373001;
when ("DETECTED") result_snomed = 260385009;
otherwise result_snomed = 10828004;
end;
end;
end;
expand this code snippet for the other tests and results.
Thank you,
I expanded this to:
select (test_loinc);
when ("94759-8") do;
select (upcase(test_result));
when ("DETECTED") result_snomed = 260373001;
when ("NEGATIVE") result_snomed = 260385009;
when ("POSITIVE") result_snomed = 10828004;
otherwise result_snomed = 260415000;
end;
select (lowcase(test_result));
when ("detected") result_snomed = 260373001;
when ("negative") result_snomed = 260385009;
when ("positive") result_snomed = 10828004;
otherwise result_snomed = 260415000;
end;
select (propcase(test_result));
when ("Detected") result_snomed = 260373001;
when ("Negative") result_snomed = 260385009;
when ("Positive") result_snomed = 10828004;
otherwise result_snomed = 260415000;
end;
end;
when ("94558-4") do;
select (upcase(test_result));
when ("DETECTED") result_snomed = 260373001;
when ("NEGATIVE") result_snomed = 260385009;
when ("POSITIVE") result_snomed = 10828004;
otherwise result_snomed = 260415000;
end;
select (lowcase(test_result));
when ("detected") result_snomed = 260373001;
when ("negative") result_snomed = 260385009;
when ("positive") result_snomed = 10828004;
otherwise result_snomed = 260415000;
end;
select (propcase(test_result));
when ("Detected") result_snomed = 260373001;
when ("Negative") result_snomed = 260385009;
when ("Positive") result_snomed = 10828004;
otherwise result_snomed = 260415000;
end;
end;
end;
Does it look fine? Especially for the use of end;
Thank you,
Razina
There are 2 values for "test_loinc" and more values for "test_result" such as results with all lower case and results with mixedletters (first letter only upper case).
Thank you,
Razina
What @gamotte said. By testing for UPCASE once you can cover all eventualities, most of your code is redundant.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.