My difficulty is understanding this sentence so as to write the code. Identify encounters that are missing medication data by: Setting Source Hospital Identifier To my knowledge, I interpreted it as identifying missing values by setting so I thought about using "if then/else. The variables are char variables. I feel I did not interpret the statement correctly. Help !!
data drug;
set Im.med;
if encounter_id = " " then setting = " ";
else if enconter_id = " " then setting = " ";
run;
Sorry to give you an answer that you don't want to hear, but this is not a SAS problem. You ought to consult with the subject matter experts and your company or university who can explain what is needed here.
It would likely help to provide some examples of your data with some records showing some missing medication data and others not.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
here is a fair link to get you started.
https://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000202239.htm
basically if condition is meet the statement is set else if the condition fails then the else condition is tested. and so on and so on for each else condition until a condition is set.
there are much better ways to handle setting variables but your basic if then else is a fair starting point.
Identify encounters that are missing medication data by: Setting Source Hospital Identifier
This seems incomplete? Missing medication is relatively easy, personally I prefer to use the MISSING() function because it doesn't matter if the variable is character or numeric.
if missing(encounter_id) then
BUt why are you checking if the encounterID is missing, when it asks about medication?
We really can't answer this at all, because we don't know the data, context or question.
@CathyVI wrote:
My difficulty is understanding this sentence so as to write the code. Identify encounters that are missing medication data by: Setting Source Hospital Identifier To my knowledge, I interpreted it as identifying missing values by setting so I thought about using "if then/else. The variables are char variables. I feel I did not interpret the statement correctly. Help !!
data drug;
set Im.med;
if encounter_id = " " then setting = " ";
else if enconter_id = " " then setting = " ";
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.