Hi,
Please find the code below.
Basing on one of the following conditions are TRUE/FALSE=, the output EARLYD is generated as YES or NO.
There are multiple records for one ID. However, I am having trouble generating the F_EarlyD(column). I have attached the excel with the expected output for reference.
Any help is appreciated.
data d4;
attrib EarlyD length=$4;
by ID;
if (upcase (AUNIT) = 'U/L' AND (AT > 2000)) or
(upcase (AUNIT) = 'μkat/L' AND (AT > 33.3)) or
(upcase (AST) = 'BILIRUBIN LEVEL' AND upcase(ASUNIT) = 'MG/DL' AND (ASUNIT > = 10)) or
(upcase(AST) = 'BILIRUBIN LEVEL' AND upcase(ASUNIT) = 'μMOL/L' AND (ASUNIT > = 171.0367)) or
(upcase(AST) eq 'INR LEVEL' AND (ASUNIT >= 1.6)) or
(upcase(PRIMYN) = 'Yes')
then EarlyD="Yes";
else EarlyD="No";
run;
Output_Expected:
ID | EarlyD? | F_EarlyD |
01-001 | Yes | Yes |
01-001 | No | |
01-001 | No | |
01-001 | No | |
01-001 | No | |
01-001 | No | |
01-001 | No | |
01-002 | No | No |
01-002 | No | |
01-003 | Yes | Yes |
01-004 | Yes | Yes |
01-004 | Yes | |
01-004 | Yes | |
01-005 | No | No |
01-005 | No | |
01-005 | No | |
Thank you,
Regards,
Nasya
@Nasya,
Can you give this a shot and let me know if this works ?
data d4;
attrib EarlyD length=$4;
by ID;
if (upcase (AUNIT) = 'U/L' AND (AT > 2000)) Then EarlyD="Yes";
else if (upcase (AUNIT) = 'μkat/L' AND (AT > 33.3)) Then EarlyD="Yes";
else if (upcase (AST) = 'BILIRUBIN LEVEL' AND upcase(ASUNIT) = 'MG/DL' AND (ASUNIT > = 10)) Then EarlyD = "Yes";
else if (upcase(AST) = 'BILIRUBIN LEVEL' AND upcase(ASUNIT) = 'μMOL/L' AND (ASUNIT > = 171.0367)) Then EarlyD = "Yes";
else if (upcase(AST) = 'BILIRUBIN LEVEL' AND upcase(ASUNIT) = 'μMOL/L' AND (ASUNIT > = 171.0367)) Then EarlyD = "Yes";
else if (upcase(AST) eq 'INR LEVEL' AND (ASUNIT >= 1.6)) Then EarlyD = "Yes";
else if (upcase(PRIMYN) = 'Yes') then EarlyD="Yes";
else EarlyD="No";
run;
Just to test it, you may even try running it on one of the SASHelp Datasets like in the example shown below:
data want;
set sashelp.class;
if age > 13 and sex = 'F' and weight > 55 then cond1 = "yes";
else if age < 13 and sex = 'M' and weight > 57 then cond1 = "yes";
else cond1 = "no";
run;
Hi UdayGuntupalli,
I tried the code that you sent me, but it is not giving me the expected output. All the multiple values are being generated in the output as earlier. Is there any other way to fix it?
Thank you,
Regards,
Nasya
@Nasya,
Can you share a sample data set or some code that generates some sample data that provides an example of the data you are working with ? It will be easier to work with the data to trouble shoot the issue or test it in sample data as I showed above.
Here are a couple of places to start.
I'm not sure what the upper case of μ would be, you might need to test that.
But I'm 100% sure that when you apply UPCASE to AUNIT, it would never contain lower-case letters like "kat".
Also, you are using ASUNIT incorrectly in a couple of places. One of these must be wrong:
upcase(ASUNIT) = 'MG/DL' AND (ASUNIT > = 10)
Is ASUNIT character (and comparable to MG/DL) or is it numeric (and comparable to 10) ?
That's at least a good place to start. If you notice further problems, it would be a good idea to post the log next time.
Hi,
Thanks for your response, I will check on the UPCASE conditions.
Regards,
Nasya
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.