Hi all,
I have an example data below. What I want is:
I have a new column named Toxicity. If HGB > 8.0 and retic > 0.08 occurs at the same time, then Toxicity = "None", otherwise Toxicity = "Yes"
I don't know how to do with multiple if conditions but different event names...any idea?
data Lab; input ID Event $ Result; datalines; 1 ANC 3200 1 HGB 7.7 1 Retic 0.3839 1 Platelet 384 2 ANC 1500 2 HGB 9.3 2 Retic 0.1118 2 Platelet 232 3 ANC 2000 3 HGB 10.4 3 Retic 0.2987 3 Platelet 418 ; run;
in my example, the Toxicity with "None" should be ID = 2 and ID = 3.
Thanks,
C
Proc transpose for HGB and Retic to determinate the status of Toxicity. Then merge back with lab data by id. Sample codes are below
proc transpose data=lab out=Toxicity;
by id;
where event in('HGB' 'Retic');
var result;
id event;
run;
data Toxicity;
length Toxicity $10;
set Toxicity;
if HGB > 8 and Retic > 0.08 then Toxicity = "YES";
else Toxicity = "None";
keep id Toxicity;
run;
data want;
merge lab Toxicity;
by id;
run;
Please show what you expect the output to look like.
Since your data set is in terms of Event And Result then it appears that you want to set toxicity for ID based on two different Events.
Are the order of HGB and Retic for Event within ID always the same with Event=HGB always followed by Event=Retic?
my expected output should be:
ID | Event | Result | Toxicity |
1 | ANC | 3200 | None |
1 | HGB | 7.7 | None |
1 | Retic | 0.3839 | None |
1 | Platelet | 384 | None |
2 | ANC | 1500 | Yes |
2 | HGB | 9.3 | Yes |
2 | Retic | 0.1118 | Yes |
2 | Platelet | 232 | Yes |
3 | ANC | 2000 | Yes |
3 | HGB | 10.4 | Yes |
3 | Retic | 0.2987 | Yes |
3 | Platelet | 418 | Yes |
Yes, my conditions should be with two different events (HGB and Retic) and the order is not always HGB then Retic, it maybe orderless.
Thanks,
C
Hello,
proc sort data=Lab;
by ID;
run;
data want;
set Lab;
by ID;
retain chk;
format Toxicity $4.;
keep ID Toxicity;
if first.ID then chk=0;
if (Event="HGB" and result>8) or (Event="Retic" and result>0.08) then chk=chk+1;
if last.ID then do;
if chk=2 then Toxicity="None";
else Toxicity="Yes";
output;
end;
run;
Proc transpose for HGB and Retic to determinate the status of Toxicity. Then merge back with lab data by id. Sample codes are below
proc transpose data=lab out=Toxicity;
by id;
where event in('HGB' 'Retic');
var result;
id event;
run;
data Toxicity;
length Toxicity $10;
set Toxicity;
if HGB > 8 and Retic > 0.08 then Toxicity = "YES";
else Toxicity = "None";
keep id Toxicity;
run;
data want;
merge lab Toxicity;
by id;
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.